Skip to content

Instantly share code, notes, and snippets.

@toandv
Last active August 30, 2015 14:19
Show Gist options
  • Save toandv/5cb48f30a67ca72951eb to your computer and use it in GitHub Desktop.
Save toandv/5cb48f30a67ca72951eb to your computer and use it in GitHub Desktop.
DateTime format
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
System.out.println(objectMapper.writeValueAsString(new Entity()));
}
static class Entity {
ZonedDateTime time = ZonedDateTime.now();
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public ZonedDateTime getTime() {
return time;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment