我想java.util.Date
使用joda
. 我需要Date
课堂上的日期格式为yyyy-MMM-dd HH:mm:ss
和GMT/UTC
时间。
谢谢。
我将澄清我的问题:我希望当我打印 toString of Date 时,我将以 yyyy-MMM-dd HH:mm:ss 格式和 UTC/GMT 时间获得时间。
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MMM-dd HH:mm:ss");
DateTime jodaDate = fmt.parseDateTime(utilDate);
有从AbstractInstant继承的方法DateTime::toDate()
java.util.Date
您可以使用SimpleDateFormat进行格式化
DateTime
您可以使用DateTimeFomratter进行格式化
或者你可以扩展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);
}
}