API(新增时间)(ZoneId ZonedDateTime)

ZoneId  (时区)    ZonedDateTime(带时区的时间)   

时区:由于世界各个国家与地区的经度不同,各地区的时间也有所不同,因此会划分为不同的时区

世界标准时间:UTC

public class Text {
    public static void main(String[] args) throws CloneNotSupportedException, ParseException {

        //目标:了解时区和带时区的时间

        //1.ZoneId的常见方法
        //public static ZoneId systemDefault():获取系统默认的时区
        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println(zoneId.getId());  //Asia/Shanghai
        System.out.println(zoneId);  //Asia/Shanghai

        //public static Set<String> getAvailableZoneIds():获取Java支持的全部时区Id
        System.out.println(ZoneId.getAvailableZoneIds());

        //public static ZoneId of(String zoneId):把某个时区id封装成ZoneId对象
        ZoneId zoneId1= ZoneId.of("America/Marigot");

        //2.ZonedDateTime:带时区的时间
        //public static ZonedDateTime now(ZoneId  zone):获取某个时区的ZonedDateTime对象
        ZonedDateTime now = ZonedDateTime.now(zoneId1);
        System.out.println(now);

        //世界标准时间
        ZonedDateTime now1 = ZonedDateTime.now(Clock.systemUTC());
        System.out.println(now1);

        //public static ZonedDateTime now():获取系统默认时区的ZonedDateTime对象
        ZonedDateTime now2 = ZonedDateTime.now();
        System.out.println(now2);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值