August 2004
Intermediate to advanced
480 pages
9h 41m
English
The following class contains methods for formatting times in ways you are likely to want to do.
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() ...Read now
Unlock full access