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 なぜですか? 誰でも説明できますか?
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 なぜですか? 誰でも説明できますか?
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?)
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Read the API again. The time symbols are not all lower case characters.
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");