JAVA8 时间格式转换


 

 

 

DateTimeFormatter formatter= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//对象转字符串
String timeStr = formatter.format(LocalDateTime.now());
System.out.println(timeStr);

//字符串转对象
LocalDateTime time = LocalDateTime.parse("2020-10-11 12:23:34",formatter);
System.out.println(time);

//对象转long(秒数)
Long seconds = time.toEpochSecond(ZoneOffset.of("+8"));
System.out.println(seconds);

//long转对象
LocalDateTime time2 = LocalDateTime.ofEpochSecond(1602390214,0,ZoneOffset.of("+8"));
System.out.println(time2);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM