集册 Java实例教程 创建ZoneOffset类的实例

创建ZoneOffset类的实例

欢马劈雪     最近更新时间:2020-01-02 10:19:05

568
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建ZoneOffset类的实例
/**
来 自 N o w J a v a . c o m
**/

import java.time.ZoneOffset;


public class Main {

  public static void main(String[] args) {

    // Create zone-offset using hour, minute, and second

    ZoneOffset zos1 = ZoneOffset.ofHours(-6);

    ZoneOffset zos2 = ZoneOffset.ofHoursMinutes(5, 30);

    ZoneOffset zos3 = ZoneOffset.ofHoursMinutesSeconds(8, 30, 45);

    System.out.println(zos1);

    System.out.println(zos2);

    System.out.println(zos3);


    // Create zone-offset using offset ID as a string

    ZoneOffset zos4 = ZoneOffset.of("+05:00");

    ZoneOffset zos5 = ZoneOffset.of("Z"); // Same as ZoneOffset.UTC// 来 自 n o w    j a v a  . c o m

    System.out.println(zos4);

    System.out.println(zos5);


    // Print the values for zone offset constants

    System.out.println("ZoneOffset.UTC: "  + 
展开阅读全文