List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy"); Date date = sdf.parse("31/12/06"); System.out.println(date);/*from ww w. j a v a 2s .com*/ }
From source file:DateTest.java
public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy, MM, dd"); Date date = sdf.parse("2009, 12, 9"); System.out.println(date);// www .ja va 2 s.c om }
From source file:Main.java
public static void main(String[] args) throws Throwable { SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); Date date1 = format.parse("08:00:01"); Date date2 = format.parse("23:00:05"); Date date = new Date(date2.getTime() - date1.getTime()); System.out.println(format.format(date)); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MM/yy"); Date date = sdfSource.parse("12/11/09"); SimpleDateFormat sdfDestination = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss"); System.out.println(sdfDestination.format(date)); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy"); Date dt1 = sdf.parse("22 02 2000"); Date dt2 = sdf.parse("22 02 2010"); long diff = dt2.getTime() - dt1.getTime(); System.out.println("Days: " + diff / 1000L / 60L / 60L / 24L); }
From source file:Test.java
public static void main(String args[]) { try {//from ww w . j av a2s. co m SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD"); System.out.println(sdf.parse(args[0]).toString()); } catch (Exception e) { e.printStackTrace(); } }
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 { String dStr = "Wed, 05 Jun 2015 00:48:12 GMT"; SimpleDateFormat ft = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z"); Date t = ft.parse(dStr); TimeZone gmt = TimeZone.getTimeZone("England/London"); ft.setTimeZone(gmt);//w w w . j a v a 2s . c om System.out.println(t); System.out.println(ft.format(t)); }
From source file:Main.java
public static void main(String[] args) throws Exception { String someDate = "22/03/2015"; SimpleDateFormat strToDate = new SimpleDateFormat("dd/MM/yyyy"); Date currentDate = strToDate.parse(someDate); System.out.println("Date is : " + currentDate); String dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"; SimpleDateFormat dateToStr = new SimpleDateFormat(dateFormat); String formattedDate = dateToStr.format(currentDate); System.out.println("Formated Date is : " + formattedDate); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy", Locale.ENGLISH); System.out.println(sdf.parse("29-July-2012")); }