package egtry.date;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DisplayFormat {
public static void main(String[] args) {
Date today=new Date();
SimpleDateFormat formatter=new SimpleDateFormat("MMM dd, yyyy");
System.out.println(formatter.format(today)); //Aug 07, 2011
}
}
| Letter | Example | Comment |
|---|---|---|
| G | AD | |
| yyyy | 2011 | |
| yy | 11 | |
| MMMM | August | |
| MMM | Aug | |
| MM | 08 | |
| www | 033 | week in year |
| ww | 33 | |
| w | 33 | |
| W | 2 | week in month |
| WW | 02 | |
| WWW | 002 | |
| D | 219 | day in year |
| DD | 219 | |
| DDDD | 0219 | |
| d | 7 | day in month |
| EEE | Sun | day in week |
| EEEE | Sunday | |
| aa | PM | morning or afternoon |
| HH | 18 | has 0th hour |
| kk | 18 | 0th hour is 24th hour |
| KK | 06 | 0th hour is 12th hour |
| hh | 06 | 1-12 |
| mm | 16 | minute in hour |
| ss | 07 | second in minute |
| S | 781 | milisecond |
| SS | 781 | milisecond |
| SSS | 781 | |
| z | CDT | general time zone |
| Z | -500 | RFC 822 time zone |