Created
April 16, 2016 17:10
-
-
Save ankushs92/6d72bebec67e4b92019b62d75e00253d to your computer and use it in GitHub Desktop.
Converting LocalDateTime object to some String pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Format : dd-MM-yyyy HH:mm | |
// Use case : LocalDateTime object to Json serialization. | |
final LocalDateTime dateTime = LocalDateTime.now() ; //or something else. | |
final int day = dateTime.getDayOfMonth(); | |
final int month = dateTime.getMonthValue(); | |
final int year = dateTime.getYear(); | |
final int hour = dateTime.getHour(); | |
final int minute = dateTime.getMinute(); | |
jsonGenerator.writeString(new StringBuilder() | |
.append(day).append("-") | |
.append(month).append("-") | |
.append(year).append(" ") | |
.append(hour).append(":") | |
.append(minute) | |
.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment