1
Timestamp tsmp = Timestamp.valueOf("0302-02-20 00:00:00");
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(df.format(tsmp));

このコード セグメントは次のように出力します: 0302-02-20 12:00:00 なぜですか? 誰でも説明できますか?

4

3 に答える 3

8

You're using hh, which is 12-hour format ("Hour in am/pm (1-12)" as specified in the docs). Use HH instead.

final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

You should pretty much never use hh unless you're also using a, the AM/PM designator.

(Did you really mean to create a timestamp in the year 302AD though, out of interest?)

于 2013-06-12T04:40:39.787 に答える
3

new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

Read the API again. The time symbols are not all lower case characters.

于 2013-06-12T04:40:36.970 に答える
2

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

于 2013-07-15T07:36:53.110 に答える