1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/* Formatting TimeZone using SimpleDateFormat This example shows how to format TimeZone using Java SimpleDateFormat class. TimeZone can be formatted in either z, zzzz or Z formats. */ import java.text.SimpleDateFormat; import java.util.Date; public class FormattingTimeZone { public static void main(String[] args) { //create Date object Date date = new Date(); //formatting TimeZone in z (General time zone) format like EST. String strDateFormat = "zzz"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("TimeZone in z format : " + sdf.format(date)); //formatting TimeZone in zzzz format Eastern Standard Time. strDateFormat = "zzzz"; sdf = new SimpleDateFormat(strDateFormat); System.out.println("TimeZone in zzzz format : " + sdf.format(date)); //formatting TimeZone in Z (RFC 822) format like -8000. strDateFormat = "Z"; sdf = new SimpleDateFormat(strDateFormat); System.out.println("TimeZone in Z format : " + sdf.format(date)); } } /* Typical output would be TimeZone in z format : EST TimeZone in zzzz format : Eastern Standard Time TimeZone in Z format : -0500 */ |
Add Comment