[英]Convert from java.util.date to JodaTime
I want to convert a java.util.Date
to JodaTime
so as to carry out subtractions between dates. 我想将
java.util.Date
转换为JodaTime
以便在日期之间进行减法。 Is there a good concise way to convert from Date
to JodaTime
? 有没有一个简洁的方法从
Date
转换为JodaTime
?
java.util.Date date = ...
DateTime dateTime = new DateTime(date);
Make sure date
isn't null
, though, otherwise it acts like new DateTime()
- I really don't like that. 确保
date
不是null
,否则它就像new DateTime()
- 我真的不喜欢它。
http://joda-time.sourceforge.net/quickstart.html http://joda-time.sourceforge.net/quickstart.html
Each datetime class provides a variety of constructors. 每个datetime类都提供了各种构造函数。 These include the Object constructor.
这些包括Object构造函数。 This allows you to construct, for example, DateTime from the following objects:
这允许您从以下对象构造DateTime:
* Date - a JDK instant
* Calendar - a JDK calendar
* String - in ISO8601 format
* Long - in milliseconds
* any Joda-Time datetime class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.