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:Main.java
public static void main(String[] args) { String str_date = "2015-05-15 05:55:55.0"; DateFormat formatter;/*from w ww .j a v a2 s. co m*/ Date date; try { formatter = new SimpleDateFormat("yyyy-MM-d HH:mm:ss"); date = formatter.parse(str_date); System.out.println(date); } catch (ParseException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String text = "09/19/2014"; // Create a pattern for the date text "09/19/2014" String pattern = "MM/dd/yyyy"; SimpleDateFormat simpleFormatter = new SimpleDateFormat(pattern); // a ParsePosition object with value zero ParsePosition startPos = new ParsePosition(0); // Parse the text Date parsedDate = simpleFormatter.parse(text, startPos); System.out.println(parsedDate); }
From source file:Main.java
public static void main(String[] args) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); List<Date> otherDates = Arrays.asList(new Date[] { simpleDateFormat.parse("01.01.2015 01:00:00"), simpleDateFormat.parse("01.01.2015 01:00:02") }); System.out.println(get(otherDates, simpleDateFormat.parse("01.01.2015 01:00:01"))); System.out.println(get(otherDates, simpleDateFormat.parse("01.01.2015 01:00:03"))); System.out.println(get(otherDates, simpleDateFormat.parse("01.01.2015 01:00:00"))); }
From source file:Main.java
public static void main(String[] args) throws Exception { String laDate = "2014-06-15"; String dateString = laDate.substring(8, 10) + "/" + laDate.substring(5, 7) + "/" + laDate.substring(0, 4); Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateString); String dateFormat = "dd-MMM-yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, new Locale("en_US")); String tDate = sdf.format(date); System.out.println(tDate);/*from ww w. j a v a 2 s . com*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { String fromDateString = "Wed Jul 08 17:08:48 GMT 2015"; DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date fromDate = (Date) formatter.parse(fromDateString); TimeZone central = TimeZone.getTimeZone("America/Chicago"); formatter.setTimeZone(central);//from w w w . j a v a 2s. co m System.out.println(formatter.format(fromDate)); }
From source file:Main.java
public static void main(String[] args) { try {/*from ww w.j a v a2s. c o m*/ String str_date = "Sat Sep 8 10:13:09 GMT+0530 2012"; DateFormat formatter; Date date; formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss 'GMT'z yyyy"); date = (Date) formatter.parse(str_date); System.out.println("Today is " + date); } catch (ParseException e) { System.out.println("Exception :" + e); } }
From source file:Main.java
public static void main(String[] args) { Timestamp timestamp = new Timestamp(System.currentTimeMillis()); Date date = new Date(timestamp.getTime()); // S is the millisecond SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy' 'HH:mm:ss:S"); System.out.println(simpleDateFormat.format(timestamp)); System.out.println(simpleDateFormat.format(date)); }
From source file:Main.java
public static void main(String[] args) { String startDate = "14-08-2014"; String endDate = "21/08/2020"; SimpleDateFormat sdf[] = new SimpleDateFormat[] { new SimpleDateFormat("dd/MM/yyyy"), new SimpleDateFormat("dd-MM-yyyy") }; Date dateStart = parse(startDate, sdf); Date dateEnd = parse(endDate, sdf); System.out.println("Is today bewteen " + dateStart + " and " + dateEnd); Date today = new Date(); if (today.after(dateStart) && today.before(dateEnd)) { System.out.println("Yes"); } else {/* w w w . j a v a2s . c om*/ System.out.println("No"); } }
From source file:DateCalAdd.java
public static void main(String[] av) { /** Today's date */ Calendar now = Calendar.getInstance(); /* Do "DateFormat" using "simple" format. */ SimpleDateFormat formatter = new SimpleDateFormat("E yyyy/MM/dd 'at' hh:mm:ss a zzz"); System.out.println("It is now " + formatter.format(now.getTime())); now.add(Calendar.YEAR, -2);//from w w w. j a v a 2s. c o m System.out.println("Two years ago was " + formatter.format(now.getTime())); }
From source file:Main.java
public static void main(String[] args) { String input = "2014-05-04 09:10:40.321"; // Prepare the pattern String pattern = "yyyy-MM-dd HH:mm:ss.SSS"; SimpleDateFormat sdf = new SimpleDateFormat(pattern); // Parse the text into a Date object Date dt = sdf.parse(input, new ParsePosition(0)); System.out.println(dt);//from w w w .j av a 2 s .c o m // Get the Calendar instance Calendar cal = Calendar.getInstance(); cal.setTime(dt); // Print time parts System.out.println("Hour:" + cal.get(Calendar.HOUR)); System.out.println("Minute:" + cal.get(Calendar.MINUTE)); System.out.println("Second:" + cal.get(Calendar.SECOND)); System.out.println("Millisecond:" + cal.get(Calendar.MILLISECOND)); }