List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:Main.java
public static void main(String[] args) throws Exception { DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Date today = df.parse("20/12/2005"); System.out.println("Today = " + df.format(today)); }
From source file:Main.java
public static void main(String[] args) { DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); System.out.println("Report Date: " + reportDate); }
From source file:TimeFormatDemo.java
public static void main(String args[]) { Date date = new Date(); DateFormat df; df = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.JAPAN); System.out.println("Japan: " + df.format(date)); df = DateFormat.getTimeInstance(DateFormat.LONG, Locale.UK); System.out.println("United Kingdom: " + df.format(date)); df = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CANADA); System.out.println("Canada: " + df.format(date)); }
From source file:Main.java
public static void main(String args[]) { int style = DateFormat.MEDIUM; // Also try with style = DateFormat.FULL and DateFormat.SHORT Date date = new Date(); DateFormat df; df = DateFormat.getDateInstance(style, Locale.UK); System.out.println("United Kingdom: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.US); System.out.println("USA: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.FRANCE); System.out.println("France: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.ITALY); System.out.println("Italy: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.JAPAN); System.out.println("Japan: " + df.format(date)); }
From source file:Main.java
public static void main(String[] args) { Date now = new Date(); DateFormat defaultFormat = DateFormat.getDateTimeInstance(); String defaultString = defaultFormat.format(now); System.out.println("Default : " + defaultString); DateFormat antarcticaFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new Locale("en", "AQ")); String antarcticaString = antarcticaFormat.format(now); System.out.println("Antarctica: " + antarcticaString); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.getDefault()); String s = dateFormat.format(new Date()); System.out.println(s);/*from ww w .j a v a 2 s . c om*/ }
From source file:MainClass.java
public static void main(String args[]) { Date date = new Date(); DateFormat df; df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN); System.out.println("Japan: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.KOREA); System.out.println("Korea: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.LONG, Locale.UK); System.out.println("United Kingdom: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US); System.out.println("United States: " + df.format(date)); }
From source file:Main.java
public static void main(String[] args) { Date d = new Date(); System.out.println(d);//from w w w . j a va2 s . c o m DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone("Australia/Sydney")); System.out.println(df.format(d)); df.setTimeZone(TimeZone.getTimeZone("Europe/London")); System.out.println(df.format(d)); }
From source file:Main.java
public static void main(String[] args) { long time = System.currentTimeMillis(); Date d = new Date(time); Timestamp t = new Timestamp(time); t.setNanos(123456789);/*from w w w. ja va 2 s . co m*/ System.out.println(d); System.out.println(t); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.'"); NumberFormat nf = new DecimalFormat("000000000"); System.out.println(df.format(t.getTime()) + nf.format(t.getNanos())); }
From source file:AntarcticaLocaleDemo.java
public static void main(String [] args) { Date now = new Date(); DateFormat defaultFormat = DateFormat.getDateTimeInstance(); String defaultString = defaultFormat.format (now); System.out.println ("Default : " + defaultString); DateFormat antarcticaFormat = DateFormat.getDateTimeInstance ( DateFormat.FULL, DateFormat.FULL, new Locale ("en", "AQ")); String antarcticaString = antarcticaFormat.format (now); System.out.println ("Antarctica: " + antarcticaString); }