List of usage examples for java.text SimpleDateFormat format
public final String format(Date date)
From source file:Main.java
public static void main(String[] args) { SimpleDateFormat simpleFormatter = new SimpleDateFormat("dd/MM/yyyy"); Date today = new Date(); String formattedDate = simpleFormatter.format(today); System.out.println("Today is (dd/MM/yyyy): " + formattedDate); simpleFormatter.applyPattern("MMMM dd, yyyy"); formattedDate = simpleFormatter.format(today); System.out.println("Today is (MMMM dd, yyyy): " + formattedDate); }
From source file:Main.java
public static void main(String[] args) { Date now = new Date(); System.out.println("toString(): " + now); // dow mon dd hh:mm:ss zzz yyyy SimpleDateFormat dateFormatter = new SimpleDateFormat("E, y-M-d 'at' h:m:s a z"); System.out.println("Format 1: " + dateFormatter.format(now)); dateFormatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); System.out.println("Format 2: " + dateFormatter.format(now)); dateFormatter = new SimpleDateFormat("EEEE, MMMM d, yyyy"); System.out.println("Format 3: " + dateFormatter.format(now)); }
From source file:Main.java
public static void main(String[] args) throws Exception { String source = new String("03/20/2015"); SimpleDateFormat sdfinput = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat sdfoutput = new SimpleDateFormat("yyyy-MM-dd"); Date inputdate = sdfinput.parse(source); String outputDate = sdfoutput.format(inputdate); System.out.println(outputDate); }
From source file:Main.java
public static void main(String[] args) throws Exception { // Declare a date format for parsing SimpleDateFormat dateParser = new SimpleDateFormat("h:mm a"); // Parse the time string Date date = dateParser.parse("3:30 PM"); // Declare a date format for printing SimpleDateFormat dateFormater = new SimpleDateFormat("HH:mm"); // Print the previously parsed time System.out.println(dateFormater.format(date)); }
From source file:Main.java
public static void main(String[] args) { Date d = new Date(); SimpleDateFormat sd = new SimpleDateFormat("MMMM dd, YYYY"); SimpleDateFormat sd1 = new SimpleDateFormat("HH:mm"); String s = sd.format(d); String s1 = sd1.format(d);//ww w. jav a2 s . c o m System.out.println(s + " " + s1); }
From source file:Main.java
public static void main(final String[] args) throws ParseException { final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); f.setTimeZone(TimeZone.getTimeZone("UTC")); System.out.println(f.format(new Date())); }
From source file:Main.java
public static void main(String args[]) { String DATE_FORMAT = "yyyyMMdd"; SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); Calendar c1 = Calendar.getInstance(); // today System.out.println("Today is " + sdf.format(c1.getTime())); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date theDate = dateFormat.parse("01/01/2009"); System.out.println(dateFormat.format(theDate)); }
From source file:Main.java
public static void main(String[] args) throws Exception { long yourmilliseconds = 1119193123; SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS"); Date resultdate = new Date(yourmilliseconds); System.out.println(sdf.format(resultdate)); }
From source file:Main.java
public static void main(String[] args) { DateFormatSymbols symbols = new DateFormatSymbols(new Locale("en", "US")); String[] defaultDays = symbols.getShortWeekdays(); for (int i = 0; i < defaultDays.length; i++) { System.out.print(defaultDays[i] + " "); }// w w w .j a v a2s. c om System.out.println(); String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; symbols.setShortWeekdays(capitalDays); String[] modifiedDays = symbols.getShortWeekdays(); for (int i = 0; i < modifiedDays.length; i++) { System.out.println(modifiedDays[i] + " "); } SimpleDateFormat formatter = new SimpleDateFormat("E", symbols); Date today = new Date(); String result = formatter.format(today); System.out.println(result); }