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) { 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[]) { Date todaysDate = new java.util.Date(); // Formatting date into yyyy-MM-dd HH:mm:ss e.g 2015-10-10 11:21:10 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String formattedDate = formatter.format(todaysDate); System.out.println("Formatted date is ==>" + formattedDate); // Formatting date into yyyy-MM-dd e.g 2015-10-10 formatter = new SimpleDateFormat("yyyy-MM-dd"); formattedDate = formatter.format(todaysDate); System.out.println("Formatted date is ==>" + formattedDate); // Formatting date into MM/dd/yyyy e.g 10/10/2015 formatter = new SimpleDateFormat("MM/dd/yyyy"); formattedDate = formatter.format(todaysDate); System.out.println("Formatted date is ==>" + formattedDate); }
From source file:Main.java
public static void main(String[] args) { SimpleDateFormat sdfDate = new SimpleDateFormat("dd/MM/yyyy"); Date now = new Date(); String strDate = sdfDate.format(now); System.out.println("Date: " + strDate); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Date date = new Date(); SimpleDateFormat simpDate; simpDate = new SimpleDateFormat("EEEE MMMMM dd yyyy kk:mm:ss"); System.out.println(simpDate.format(date)); }
From source file:Main.java
public static void main(String[] args) { String strDateFormat = "EEEE"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("Current day of week in EEEE format : " + sdf.format(new Date())); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); Date workDate = simpleDateFormat1.parse("2011-11-27"); Calendar workCalendar = Calendar.getInstance(); workCalendar.setTime(workDate);/*from ww w . j a v a 2s .co m*/ SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm:ss"); Calendar time = Calendar.getInstance(); time.setTime(simpleDateFormat2.parse("06:00:00")); workCalendar.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY)); workCalendar.set(Calendar.MINUTE, time.get(Calendar.MINUTE)); workCalendar.set(Calendar.SECOND, time.get(Calendar.SECOND)); Date newWorkDate = workCalendar.getTime(); SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); System.out.println(simpleDateFormat3.format(newWorkDate)); }
From source file:Main.java
public static void main(String a[]) throws Exception { String timestampToParse = "24-Feb-2009 17:39:35"; System.out.println("Timestamp : " + timestampToParse); SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("Calendar : " + sdf.format(parseTimestamp(timestampToParse).getTime())); }
From source file:Main.java
public static void main(String[] argv) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat("yy"); formatter.set2DigitYearStart(new Date()); System.out.println(formatter.format(new Date())); }
From source file:Main.java
public static void main(String... args) { SimpleDateFormat df = new SimpleDateFormat("MM/dd/YYYY"); Calendar c = Calendar.getInstance(); System.out.println(df.format(c.getTime())); c.add(Calendar.YEAR, 60);/*from w w w . j a v a2s .c o m*/ System.out.println(df.format(c.getTime())); }
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 ww.j a v a 2 s. co m System.out.println("Two years ago was " + formatter.format(now.getTime())); }