Displaying Time In Java

Web applications frequently need to display times and dates in other timezones, not just their local time zone or UTC. Here’s a code example that takes a date and expresses it in several different time zones:

Date add_date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("MMMMMMMMMM dd, yyyy hh:mm aa");
formatter.setTimeZone(java.util.TimeZone.getTimeZone("America/Los_Angeles"));
String cali_time = formatter.format(add_date);
formatter.setTimeZone(java.util.TimeZone.getTimeZone("America/Denver"));
String denver_time = formatter.format(add_date);
formatter.setTimeZone(java.util.TimeZone.getTimeZone("America/Chicago"));
String chicago_time = formatter.format(add_date);
formatter.setTimeZone(java.util.TimeZone.getTimeZone("America/New_York"));
String ny_time = formatter.format(add_date);
formatter.setTimeZone(java.util.TimeZone.getTimeZone("France/Paris"));
String paris_time = formatter.format(add_date);
formatter.setTimeZone(java.util.TimeZone.getTimeZone("Russia/Moscow"));
String moscow_time = formatter.format(add_date);
formatter.setTimeZone(java.util.TimeZone.getTimeZone("China/Shanghai"));
String shanghai_time = formatter.format(add_date);