I'm trying to parse my DateTime
in a specific format to String
. Code:
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");
Result:
2018-01-15+0100
What I want:
2018-01-15+01:00
You should read the docs .
Zone: 'Z' outputs offset without a colon, 'ZZ' outputs the offset with a colon, 'ZZZ' or more outputs the zone id.
so your code should be:
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");
You need to use ZZ
to output with a colon. So:
String result = formattedDate.toString("yyyy-MM-ddZZ");
will output:
2018-01-15+01:00
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.