Formatting TimeZone using SimpleDateFormat
import java.text.SimpleDateFormat;
import java.util.Date;
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:
TimeZone in z format : PST
TimeZone in zzzz format : Pacific Standard Time
TimeZone in Z format : -0800
Home
Java Book
Essential Classes
Java Book
Essential Classes
SimpleDateFormat:
- SimpleDateFormat class introduction
- SimpleDateFormat formats date, day,
- Add AM PM to time format using SimpleDateFormat
- Formatting date in default formats using DateFormat
- Formatting day using SimpleDateFormat
- Formatting day of week using SimpleDateFormat
- Formatting hour using SimpleDateFormat
- Formatting hour using SimpleDateFormat: k
- Formatting Minutes using SimpleDateFormat
- Formatting month using SimpleDateFormat
- Formatting seconds using SimpleDateFormat
- Formatting TimeZone using SimpleDateFormat
- Formatting year using SimpleDateFormat
- Use various format
- Convert date string from one format to another format using SimpleDateFormat