Time Zones and java.util.Date

suggest change

A java.util.Date object does not have a concept of time zone.

However, it is possible to display the date represented by the point in time described by the Date object in a different time zone using e.g. java.text.SimpleDateFormat:

Date date = new Date();
//print default time zone
System.out.println(TimeZone.getDefault().getDisplayName());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //note: time zone not in format!
//print date in the original time zone
System.out.println(sdf.format(date));
//current time in London
sdf.setTimeZone(TimeZone.getTimeZone("Europe/London"));
System.out.println(sdf.format(date));

Output:

Central European Time
2016-07-21 22:50:56
2016-07-21 21:50:56

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Data Class:
* Time Zones and java.util.Date

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
33 Data Class
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap