【发布时间】:2018-11-12 14:15:13
【问题描述】:
下面的代码没有返回预期的输出。它有什么问题?
def a = new Test(new Date());
println a.getLogFormatDate()
class Test
{
String _dateTime;
static final String _logDateFormat = "E MMM dd HH:mm:ss zzz yyyy";
static final String _timeZoneUTC = "UTC";
Test(Date dateTime)
{
_dateTime = dateTime;
}
public String getLogFormatDate()
{
return _dateTime.format(_logDateFormat, TimeZone.getTimeZone(_timeZoneUTC));
}
}
预期输出:
2018 年 11 月 12 日星期一 14:10:46 UTC
实际输出:
E MMM dd HH:mm:ss zzz yyyy
【问题讨论】: