Java examples for java.time:LocalDateTime
LocalDateTime To String in format of dd-MM-yyyy HH:mm:ss
//package com.java2s; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Main { private static final String DATETIME_PATTERN = "dd-MM-yyyy HH:mm:ss"; public static String dateTimeToString(LocalDateTime someLocalDateTime) { return dateTimeToString(someLocalDateTime, DATETIME_PATTERN); }//from w w w . ja v a2 s .c o m public static String dateTimeToString(LocalDateTime someLocalDateTime, String pattern) { if (someLocalDateTime != null) { return DateTimeFormatter.ofPattern(pattern).format( someLocalDateTime); } else { return ""; } } }