Java tutorial
import java.time.LocalDate; import java.time.LocalTime; import java.time.Month; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.Temporal; import java.util.Locale; public class Main { public static void main(String[] args) { LocalTime lt = LocalTime.of(16, 30, 5, 78899); format(lt, "HH:mm:ss"); format(lt, "KK:mm:ss a"); format(lt, "[MM-dd-yyyy][' at' HH:mm:ss]"); ZoneId usCentral = ZoneId.of("America/Chicago"); ZonedDateTime zdt = ZonedDateTime.of(LocalDate.now(), lt, usCentral); format(zdt, "MM/dd/yyyy HH:mm:ssXXX"); format(zdt, "MM/dd/yyyy VV"); format(zdt, "[MM-dd-yyyy][' at' HH:mm:ss]"); } public static void format(Temporal co, String pattern) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US); String str = fmt.format(co); System.out.println(pattern + ": " + str); } }