List of usage examples for java.text SimpleDateFormat SimpleDateFormat
public SimpleDateFormat(String pattern)
SimpleDateFormat
using the given pattern and the default date format symbols for the default java.util.Locale.Category#FORMAT FORMAT locale. From source file:MainClass.java
public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); GregorianCalendar gc = new GregorianCalendar(); java.util.Date d = sdf.parse("12/12/2003"); gc.setTime(d);//from w ww . jav a 2 s .c om System.out.println("Input Date = " + sdf.format(d)); int dayBefore = gc.get(Calendar.DAY_OF_YEAR); gc.roll(Calendar.DAY_OF_YEAR, -1); int dayAfter = gc.get(Calendar.DAY_OF_YEAR); if (dayAfter > dayBefore) { gc.roll(Calendar.YEAR, -1); } gc.get(Calendar.DATE); java.util.Date yesterday = gc.getTime(); System.out.println("Yesterdays Date = " + sdf.format(yesterday)); }
From source file:Main.java
public static void main(String[] args) { Date date = new Date(); String strDateFormat = "E"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("Current day of week in E format : " + sdf.format(date)); }
From source file:Main.java
public static void main(String[] args) { try {//from w w w . ja v a2 s.c om String str_date = "11-June-07"; DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date date = (Date) formatter.parse(str_date); System.out.println(date); } catch (ParseException e) { System.out.println("Exception :" + e); } }
From source file:MainClass.java
public static void main(String args[]) { Date date = new Date(); SimpleDateFormat sdf;// w w w. j av a 2 s . co m sdf = new SimpleDateFormat("hh:mm:ss"); System.out.println(sdf.format(date)); sdf = new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz"); System.out.println(sdf.format(date)); sdf = new SimpleDateFormat("E MMM dd yyyy"); System.out.println(sdf.format(date)); }
From source file:Main.java
public static void main(String[] args) { String str = "Thu Jun 06 2013 00:00:00 GMT+0530"; DateFormat outputDate = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss"); try {//from w w w . j av a 2 s .c o m Date date = outputDate.parse(str); String date1 = new SimpleDateFormat("dd-mm-yyyy, hh:mm:ss").format(date); System.out.println(date1.toString()); } catch (ParseException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Date date1 = (new GregorianCalendar(2009, Calendar.OCTOBER, 17)).getTime(); System.out.println(new SimpleDateFormat("EEEE").format(date1)); }
From source file:Main.java
public static void main(String[] args) { try {//from w ww . j a v a 2 s .co m String target = "Thu Sep 28 20:29:30 JST 2015"; DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss zzz yyyy"); Date result = df.parse(target); System.out.println(result); } catch (ParseException pe) { pe.printStackTrace(); } }
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:DateParse2.java
public static void main(String[] args) { //+//from www . j a v a 2 s .c o m SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String input[] = { "BD: 1913-10-01 Vancouver, B.C.", "MD: 1948-03-01 Ottawa, ON", "DD: 1983-06-06 Toronto, ON" }; for (int i = 0; i < input.length; i++) { String aLine = input[i]; String action; switch (aLine.charAt(0)) { case 'B': action = "Born"; break; case 'M': action = "Married"; break; case 'D': action = "Died"; break; // others... default: System.err.println("Invalid code in " + aLine); continue; } int p = aLine.indexOf(' '); ParsePosition pp = new ParsePosition(p); Date d = formatter.parse(aLine, pp); if (d == null) { System.err.println("Invalid date in " + aLine); continue; } String location = aLine.substring(pp.getIndex()); System.out.println(action + " on " + d + " in " + location); } //- }
From source file:MainClass.java
public static void main(String[] a) throws Exception { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = df.parse("2001-01-01"); Date d2 = df.parse("2000-01-01"); String relation;/*from w w w. ja v a 2 s . c o m*/ if (d1.equals(d2)) relation = "the same date as"; else if (d1.before(d2)) relation = "before"; else if (d1.after(d2)) relation = "after"; System.out.println(d1 + " is " + relation + ' ' + d2); }