从 Joda-Time DateTime 中获取 java.util.Date
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4416983/
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
Get java.util.Date out from Joda-Time DateTime
提问by Cheok Yan Cheng
I have code like this:
我有这样的代码:
// old_api(Date date)
old_api(calendar.getTime());
Currently, I need to replace Calendar
with Joda-Time DateTime
. I was wondering how I can get java.util.Date
out from Joda-Time DateTime
?
目前,我需要Calendar
用 Joda-Time替换DateTime
。我想知道如何才能java.util.Date
摆脱 Joda-Time DateTime
?
采纳答案by BalusC
回答by Shailesh
One way to do that is: Extract milli-seconds from joda-datetime instance and then pass it to java.util.Date constructor.
一种方法是:从 joda-datetime 实例中提取毫秒,然后将其传递给 java.util.Date 构造函数。
Date date = new java.util.Date(jodaDateTime.getMillis())