如何从java.util.date转换为JodaTime并获取相同的日期 [英] How to convert from java.util.date to JodaTime and get same date
本文介绍了如何从java.util.date转换为JodaTime并获取相同的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循这个问题:从java.util.date转换为JodaTime
我有日期:Sun Jan 01 00:00:00 CET 1854
现在我要将其转换为joda datetime:
I have date: Sun Jan 01 00:00:00 CET 1854 now I want to convert it to joda datetime:
DateTime dateTime = new DateTime(date);
DateTime dateTime = new DateTime(date);
现在当我打印这个日期时,我得到:
1853-12-31T23:57:44.000 + 00:57:44
and now when I print this date I got: 1853-12-31T23:57:44.000+00:57:44
什么是错的,为什么我的日期变了?如何获得相同的日期?
what is wrong and why my date changed ? How I can get the same date ?
更新:
我使用日历获取日期:
Calendar cal1 = Calendar.getInstance();
cal1.set(1854, 0, 1, 0, 0, 0);
cal1.getTime()
更新2:
绝对有几分之一的问题:
propably there is problem with milseconds:
Calendar cal1 = Calendar.getInstance();
cal1.set(1854, 0, 1, 0, 0, 0);
DateTime start = new DateTime(1854, 1, 1, 0, 0, 0);
System.out.println(start.getMillis());
System.out.println(cal1.getTime().getTime());
因为此代码返回:
-3660598664000
-3660598799438
但是我不知道为什么
更新3:
推荐答案
是不是很好,但它的作品是重要的
ok I solve it. Is isnt nice but it works what is important
Calendar calendar = Calendar.getInstance();
calendar.setTime(datum);
DateTime current = new DateTime(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
这篇关于如何从java.util.date转换为JodaTime并获取相同的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文