The requirement is to simply to get the current wall time (including the correct DST adjustment) for a given Time Zone.
There seems to be a few questi
I find the following to be the cleanest method.
DateTime currentTime = DateTime.now( DateTimeZone.UTC );
This gets you the current time in UTC but this value can be converted to another DateTimeZone
or you can replace DateTimeZone.UTC
with a different DateTimeZone
.
If you want to set it to the system timezone, you can use this:
DateTime currentTime = DateTime.now( DateTimeZone.getDefault() );
Have you looked at the DateTime
constructor:
DateTime(DateTimeZone zone)
This constructs a DateTime representing the current time in the specified timezone.
How about:
DateTime utc = new DateTime(DateTimeZone.UTC);
DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
DateTime losAngelesDateTime = utc.toDateTime(tz);