SimpleDateFormat to format TimeZone

In this chapter you will learn:

  1. Formatting TimeZone using SimpleDateFormat

Formatting TimeZone using SimpleDateFormat

zzz shows the short form, while zzzz makes SimpleDateFormat to display the time zone information in a full length form. Z tells you the offset.

import java.text.SimpleDateFormat;
import java.util.Date;
/*from   j  a  v a2s .co m*/
public class Main {
  public static void main(String[] args) {
    Date date = new Date();
    // formatting TimeZone in z (General time zone) format like EST.

    SimpleDateFormat sdf = new SimpleDateFormat("zzz");
    System.out.println("TimeZone in z format : " + sdf.format(date));
    // formatting TimeZone in zzzz format Eastern Standard Time.

    sdf = new SimpleDateFormat("zzzz");
    System.out.println("TimeZone in zzzz format : " + sdf.format(date));
    // formatting TimeZone in Z (RFC 822) format like -8000.

    sdf = new SimpleDateFormat("Z");
    System.out.println("TimeZone in Z format : " + sdf.format(date));
  }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. Formatting year using SimpleDateFormat
Home » Java Tutorial » Date, Time, Calendar, TimeZone

Date

    Date class
    Date comparison
    Converting date value
    DateFormat class
    Format time
    DateFormat and Locale
    Convert String to Date

Calendar

    Calendar class
    Calendar date time getter
    Calendar set hour,minute,second
    Calendar calculation
    Calendar comparison
    Calendar properties
    GregorianCalendar

TimeZone

    TimeZone
    TimeZone ID and display name
    TimeZone daylight saving

DateFormat

    DateFormat class
    Format time
    DateFormat and Locale
    Convert String to Date
    SimpleDateFormat
    Parse date string into Date object
    SimpleDateFormat day format
    SimpleDateFormat Hour Time format
    SimpleDateFormat format minute
    SimpleDateFormat to format month
    SimpleDateFormat to format second value
    SimpleDateFormat to format TimeZone
    SimpleDateFormat to format year
    SimpleDateFormat to combine formatting flags