使用 joda-time 和 parseDateTime 忽略秒的小数部分格式化日期时间
Formatting datetime using joda-time and parseDateTime ignoring fraction of second
我需要格式化某个时区的时间。
我得到的输入日期字符串是“2015-09-21T09:00:00+02:00”类型
我用来执行此操作的代码是
DateTimeZone fromTimeZone = DateTimeZone.forID("Europe/Paris");
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withZone(fromTimeZone);
DateTime cetDateTime = fmt.parseDateTime(inputDate);
return cetDateTime.toString();
但是这个 returns “2015-09-21T09:00:00.000+02:00” 添加了秒的小数部分。有什么办法可以抑制上述字符串中的分数吗?
你可以
return fmt.print(cetDateTime);
我需要格式化某个时区的时间。 我得到的输入日期字符串是“2015-09-21T09:00:00+02:00”类型 我用来执行此操作的代码是
DateTimeZone fromTimeZone = DateTimeZone.forID("Europe/Paris");
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withZone(fromTimeZone);
DateTime cetDateTime = fmt.parseDateTime(inputDate);
return cetDateTime.toString();
但是这个 returns “2015-09-21T09:00:00.000+02:00” 添加了秒的小数部分。有什么办法可以抑制上述字符串中的分数吗?
你可以
return fmt.print(cetDateTime);