网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Java8中时间转换代码实例

这篇文章主要介绍“Java8中时间转换代码实例”,在日常操作中,相信很多人在Java8中时间转换代码实例问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Java8中时间转换代码实例”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联专业为企业提供佛山网站建设、佛山做网站、佛山网站设计、佛山网站制作等企业网站建设、网页设计与制作、佛山企业网站模板建站服务,十载佛山做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

1.将LocalDateTime转为自定义的时间格式的字符串

public static String getDateTimeAsString(LocalDateTime localDateTime, String format) {  DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);  return localDateTime.format(formatter);}

2.将long类型的timestamp转为LocalDateTime

public static LocalDateTime getDateTimeOfTimestamp(long timestamp) {  Instant instant = Instant.ofEpochMilli(timestamp);  ZoneId zone = ZoneId.systemDefault();  return LocalDateTime.ofInstant(instant, zone);}

3.将LocalDateTime转为long类型的timestamp

public static long getTimestampOfDateTime(LocalDateTime localDateTime) {  ZoneId zone = ZoneId.systemDefault();  Instant instant = localDateTime.atZone(zone).toInstant();  return instant.toEpochMilli();}

4.将某时间字符串转为自定义时间格式的LocalDateTime

public static LocalDateTime parseStringToDateTime(String time, String format) {  DateTimeFormatter df = DateTimeFormatter.ofPattern(format);  return LocalDateTime.parse(time, df);}

到此,关于“Java8中时间转换代码实例”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


本文题目:Java8中时间转换代码实例
本文地址:http://bjjierui.cn/article/gghose.html

其他资讯