Problem:
When parsing a java.util.Date from a string without explicit timezone information, the system's local time zone is automatically assigned to the resulting Date object. This may not be desirable in cases where a specific time zone needs to be specified.
Solution:
To set a custom time zone for a Date object, you can use the DateFormat class. Here's an example using SimpleDateFormat:
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); isoFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = isoFormat.parse("2010-05-23T09:01:02");
In this example:
The above is the detailed content of How Do I Set a Specific Time Zone for a Java Date Object?. For more information, please follow other related articles on the PHP Chinese website!