我正在尝试将特定格式的 DateTime
解析为 String
。
代码:
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyy-MM-dd'T'HH:mm:ss").withOffsetParsed();
DateTime formattedDate = fmt.parseDateTime(asString($client/date));
String result = formattedDate.toString("yyyy-MM-ddZ");
结果:
2018-01-15+0100
我想要什么:
2018-01-15+01:00
最佳答案
您应该阅读docs .
Zone: 'Z' outputs offset without a colon, 'ZZ' outputs the offset with a colon, 'ZZZ' or more outputs the zone id.
所以你的代码应该是:
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyy-MM-dd'T'HH:mm:ss").withOffsetParsed();
Date formattedDate = fmt.parseDateTime(asString($client/date));
String result = formattedDate.toString("yyyy-MM-ddZZ");
关于java - 如何获得 Joda DateTime 时区的冒号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48406713/