从 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 17:15:21  来源:igfitidea点击:

Get java.util.Date out from Joda-Time DateTime

javajodatime

提问by Cheok Yan Cheng

I have code like this:

我有这样的代码:

// old_api(Date date)
old_api(calendar.getTime());

Currently, I need to replace Calendarwith Joda-Time DateTime. I was wondering how I can get java.util.Dateout from Joda-Time DateTime?

目前,我需要Calendar用 Joda-Time替换DateTime。我想知道如何才能java.util.Date摆脱 Joda-Time DateTime

采纳答案by BalusC

Use DateTime#toDate().

使用DateTime#toDate().

Date date = dateTime.toDate();

回答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())