从 org.joda.time.DateTime 转换为 java.util.Calendar 的方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/363930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Approach to convert from org.joda.time.DateTime to java.util.Calendar
提问by
Anyone done this and can share? I see an option or two but want to know what others have accomplished.
有谁做过这个并且可以分享吗?我看到了一两个选项,但想知道其他人取得了什么成就。
回答by Esko
According to joda-time documentation the preferred method to use is to call this: AbstractDateTime#toCalendar.
根据 joda-time 文档,首选使用的方法是调用: AbstractDateTime#toCalendar。
回答by Michael Krauklis
You can also call AbstractInstant#toDate
你也可以调用 AbstractInstant#toDate
http://joda-time.sourceforge.net/api-release/org/joda/time/base/AbstractInstant.html#toDate()
http://joda-time.sourceforge.net/api-release/org/joda/time/base/AbstractInstant.html#toDate()
回答by Carlos D. Garza
in the 2.1 you can use
在 2.1 你可以使用
public static Calendar parseCalendar(DateTime dt){
return dt.toGregorianCalendar();
}