Skip to content

Instantly share code, notes, and snippets.

@ankushs92
Created April 16, 2016 17:10
Show Gist options
  • Save ankushs92/6d72bebec67e4b92019b62d75e00253d to your computer and use it in GitHub Desktop.
Save ankushs92/6d72bebec67e4b92019b62d75e00253d to your computer and use it in GitHub Desktop.
Converting LocalDateTime object to some String pattern
// 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