2

When UTC date is formatted by DateFormat#format(), I expect to get a String of UTC date formatted, but not.

Please look at the code below. These tests are passed.

My question is why does DateFormat#format() return a time of 12:00 past UTC date? What am I missing here?

Date date(int millisecondsSinceEpoch, bool isUtc) =>
    new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc:isUtc);

DateFormat df = new DateFormat("yyyy-MM-dd hh:mm");

// JST (+9.00)
expect(date(0, false).toString(), equals("1970-01-01 09:00:00.000"));
expect(df.format(date(0, false)), equals("1970-01-01 09:00"));

expect(date(0, true).toString(), equals("1970-01-01 00:00:00.000Z"));
// Why 12 o'clock?
expect(df.format(date(0, true)), equals("1970-01-01 12:00"));
4

1 回答 1

1

您编写的格式字符串使用小写字母hh,即 12 小时制。使用大写HH的小时来获得 24 小时制。您在最后一行得到的输出当前是午夜 12 点,而不是 24 小时制的 00 小时。

请参阅DateFormat中的显式模式语法

于 2013-01-12T15:24:51.337 回答