Time

The following class contains methods for formatting times in ways you are likely to want to do.

Times.java

 package net.dates; import java.util.*; import java.text.*; public class Times { Calendar calendar = Calendar.getInstance(); public static void main(String...a) { log(get24HourTime() ); log(getAMPMTime() ); log( getSimpleTime() ); } /** * Returns time in this format: * 14.36.33 */ public static String get24HourTime() { Date d = new Date(); Format formatter = new SimpleDateFormat("HH.mm.ss"); return formatter.format(d); } /** * Returns time in this format: * 01:12:53 AM */ public static String getAMPMTime() { Format formatter = new SimpleDateFormat("hh:mm:ss a"); return formatter.format(new Date()); } public static String getSimpleTime() ...

Get Java Garage now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.