[英]java.util.Date class using joda
I want to get a java.util.Date
class using joda
. 我想使用joda
获取一个java.util.Date
类。 I need that the date in Date
class will be format as yyyy-MMM-dd HH:mm:ss
and GMT/UTC
time. 我需要Date
类中的Date
格式设置为yyyy-MMM-dd HH:mm:ss
和GMT/UTC
时间。
Thanks. 谢谢。
I will clarify my question: i want that when i print toString of Date i will get the time in format of yyyy-MMM-dd HH:mm:ss and as UTC/GMT time. 我将澄清我的问题:我希望当我打印日期的toString时,我将以yyyy-MMM-dd HH:mm:ss的格式以及UTC / GMT时间获得时间。
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MMM-dd HH:mm:ss");
DateTime jodaDate = fmt.parseDateTime(utilDate);
There is method DateTime::toDate() inherited from AbstractInstant 有一个方法DateTime :: toDate()从AbstractInstant继承
You can format java.util.Date
with 您可以使用以下格式设置java.util.Date
SimpleDateFormat SimpleDateFormat
and you can format DateTime
with 您可以使用以下格式设置DateTime
DateTimeFomratter DateTimeFomratter
Or you can extend Date
class 或者您可以扩展Date
类
public class MyDate extends Date
{
private SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
public MyDate(Date date)
{
super(date.getTime());
}
@Override
public String toString()
{
return FORMATTER.format(this);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.