LocalDat类

LocalDat类

LocalDate.of(int year, int month, int dayOfMonth) 按指定日期创建LocalDate对象
getYear:返回日期中的年份
getMonth:返回日期中的月份
getDayOfMonth:返回月份中的日

		LocalDate date = LocalDate.now();
        System.out.println(date);
        System.out.println(date.getYear()+">>>>>"+date.getMonth()+">>>>>"+date.getDayOfMonth());

结果:
在这里插入图片描述
LocalTime.now():获取系统当前时间
LocalTime.of(int hour, int minute, int second)按指定时间创建LocalTime对象
getHour():返回小时
getMinute():返回分钟
getSecond():返回秒

   	   LocalTime time = LocalTime.now();
       System.out.println(time);
       System.out.println(time.getHour()+"时>>>>>"+time.getMinute()+"分>>>>>"+time.getSecond()+"秒>>>>");

结果:
在这里插入图片描述
* LocalDateTime.now():获取系统当前时间
*
* LocalDateTime.of(int year, int month, int dayOfMonth, int hour, int minute, int second)指定日期和时间创建LocalDateTime对象。
*
* getYear:返回日期中的年份
*
* getMonth:返回日期中的月份
*
* getDayOfMonth:返回月份中的日
*
* getHour():返回小时
*
* getMinute():返回分钟
*
* getSecond():返回秒

	    LocalDateTime now = LocalDateTime.now();
        System.out.println(now.getYear()+"年"+now.getMonth()+"月"+now.getDayOfMonth()+"日"+now.getHour()+"时"+now.getMinute()+"分"+now.getSecond()+"秒");

结果:
在这里插入图片描述
* DateTimeFormatter类
* (1)ofPatter(String pattern):按pattern字符串指定的格式创建
*
* (2)LcalDateTime.parse(strDate, formatter):

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse("2022-02-22 22:22:22", formatter);
        System.out.println(parse + ">>>class:"+parse.getClass());

        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("MM/dd/yyyy:HH:mm:ss");
        String strDate = now.format(formatter2);
        System.out.println(strDate + ">>>class:"+strDate.getClass());

结果:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值