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;
/*j  av a2s . c om*/
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