惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
B
Blog
罗磊的独立博客
GbyAI
GbyAI
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏

博客园 - 在下刚哥

ABP配置时间格式 List与String、数组的相互转换 Json转换 黑龙江社保电话 List与String的相互转换(C#) ServiceStack.Redis的GetTypedClient C# 16进制转换10进制 揭秘人体24小时 四年一轮回 .cs编译DLL类库方法 类命名规范、数据库命名规范和页面文件命名规范 SHTML和HTML的区别 NavigateUrl属性绑定 - 在下刚哥 - 博客园 让IT工作者过劳的13个坏习惯 腾讯笔试题--国王招来100个囚犯(转) 很牛的求职经历(转) 中国各城市经纬度数据 Microsoft Visual Source Safe 2005 下载地址 Fckeditor在.net下用验证控件问题
Java Instant\Date\LocalDateTime\Calendar\ZonedDateTime转...
在下刚哥 · 2022-06-27 · via 博客园 - 在下刚哥
public static Instant toInstant(Date date) {
return Instant.ofEpochMilli(date.getTime());
}
public static Date toDate(Instant instant) {
return new Date(instant.toEpochMilli());
}
public static Date toDate(LocalDateTime ldt) {
return new Date(ldt.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
}
public static Calendar toCalendar(ZonedDateTime zdt) {
TimeZone tz = TimeZone.getTimeZone(zdt.getZone());
Calendar calendar = Calendar.getInstance(tz);
calendar.setTimeInMillis(zdt.toInstant().toEpochMilli());
return calendar;
}

public static LocalDateTime toLocalDateTime(Date date) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
}

public static ZonedDateTime toZonedDateTime(Calendar calendar) {
ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(calendar.getTimeInMillis()), calendar.getTimeZone().toZoneId());
return zdt;
}