Java JodaTime 错误的秒格式
Java JodaTime wrong seconds format
DateTime now = new DateTime(2017, 2, 27, 17, 50, 31);
System.out.println(now.toString("s") + " <-- must 3\n" + now.toString("ss")+" <-- must 31");
输出:
31 <-- must 3
31 <-- must 31
有时我得到的正确结果大多是错误的!
JodaTime 2.9.7
来自 DateTimeFormat
的 Javadoc:
Number: The minimum number of digits. Shorter numbers are zero-padded to this amount. When parsing, any number of digits are accepted
因此s
指定输出必须至少一位。如果秒数小于 10,它将是一位数,但如果数字 ≥ 10,你将得到两位数。
顺便说一句,将数值 31
截断为 3
.
绝对没有意义
DateTime now = new DateTime(2017, 2, 27, 17, 50, 31);
System.out.println(now.toString("s") + " <-- must 3\n" + now.toString("ss")+" <-- must 31");
输出:
31 <-- must 3
31 <-- must 31
有时我得到的正确结果大多是错误的!
JodaTime 2.9.7
来自 DateTimeFormat
的 Javadoc:
Number: The minimum number of digits. Shorter numbers are zero-padded to this amount. When parsing, any number of digits are accepted
因此s
指定输出必须至少一位。如果秒数小于 10,它将是一位数,但如果数字 ≥ 10,你将得到两位数。
顺便说一句,将数值 31
截断为 3
.