Yes, you should use Joda-Time or the new java.time package in Java 8 (inspired by Joda-Time).
The offset is the number of hours and minutes from UTC (GMT), which is represented by a specific date-time value. The west coast is -08: 00 (ignoring the pointlessness of daylight saving time), which means 8 hours behind UTC.
Beware that java.time in its original release has a small error where it cannot handle the offset of the entire hours (e.g. +08 ) without minutes (e.g. +08:00 ).
A time zone is an offset plus daylight saving time (DST) rules, a history of DST changes, and information about other anomalies.
Use the correct time zone names (mostly a city with a slash). Avoid 3 or 4 letter codes, such as EST, that are neither standardized nor unique.
Java.util.Date does not have a time zone, but a Joda-Time DateTime .
To get the time zone of a web browser, see this question . But often this does not work well. As you've probably seen, many websites ask users to select a time zone.
Your specific use case is confusing. As a rule, the best approach is to use date-time for UTC, and then, if necessary, adjust the user’s local time. It is usually best for your software to work and store date-time in UTC. Then specify the local date-time adjusted in accordance with the requirements of the user. In other words, think around the world (UTC) while locally (local time zone is set).
Typically, system administrators store their server computers in UTC (without a time zone offset). If your OS (e.g. Mac OS X) does not offer UTC, use Reykjavik , since Iceland uses UTC year-round without daylight saving time. Similarly, databases almost always convert date and time values to UTC for storage.
Joda-Time offers the LocalDate class if you really don't like the time zone or time. But it is often better to use a date-to-date (DateTime instance) and format the date string only as needed.
Sample code in Joda-Time 2.3.
DateTimeZone timeZoneChina = DateTimeZone.forID( "Asia/Shanghai" ); DateTime dateTimeChina = new DateTime( 2013, 8, 29, 17, 45, 00, timeZoneChina ); DateTime dateTimeUtc = dateTimeChina.withZone( DateTimeZone.UTC ); DateTime dateTimeParis = dateTimeChina.withZone( DateTimeZone.forID( "Europe/Paris" ) ); DateTimeZone timeZoneUsWestCoast = DateTimeZone.forID( "America/Los_Angeles" ); DateTime dateTimeUnitedStatesWestCoast = dateTimeChina.withZone( timeZoneUsWestCoast ); DateTimeFormatter formatter = ISODateTimeFormat.date(); String outputDateOnlyForUnitedStatesWestCoast = formatter.withZone( timeZoneUsWestCoast ).print( dateTimeUtc );
Dump for console ...
System.out.println( "dateTimeChina: " + dateTimeChina ); System.out.println( "dateTimeUtc: " + dateTimeUtc ); System.out.println( "dateTimeParis: " + dateTimeParis ); System.out.println( "dateTimeUnitedStatesWestCoast: " + dateTimeUnitedStatesWestCoast ); System.out.println( "outputDateOnlyForUnitedStatesWestCoast: " + outputDateOnlyForUnitedStatesWestCoast );
At startup ...
dateTimeChina: 2013-08-29T17:45:00.000+08:00 dateTimeUtc: 2013-08-29T09:45:00.000Z dateTimeParis: 2013-08-29T11:45:00.000+02:00 dateTimeUnitedStatesWestCoast: 2013-08-29T02:45:00.000-07:00 outputDateOnlyForUnitedStatesWestCoast: 2013-08-29