JAVA8 LocalDateTime

2021-05-06 16:28

阅读:428

标签:mes   color   span   now()   str   epo   eof   ant   off   

LocalDateTime String

//时间转字符串格式化
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
String dateTime = LocalDateTime.now(ZoneOffset.of("+8")).format(formatter);

//字符串转时间
String dateTimeStr = "2018-07-28 14:11:15";
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, df);

 

 

 

LocalDateTime获取毫秒数

//获取秒数
Long second = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
//获取毫秒数
Long milliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();

 

JAVA8 LocalDateTime

标签:mes   color   span   now()   str   epo   eof   ant   off   

原文地址:https://www.cnblogs.com/bors/p/LocalDateTime.html


评论


亲,登录后才可以留言!