I have variable that store data datetime UTC from database. I want to make it in Local datetime format, can i do that?
for example:
Date dateFromDB = getfromDB();
dateFromDB = UTCtoLocalTimezone(dateFromDB);
What the code in method UTCtoLocalTimezone?
Or do you have any better solution?
thankyou!
Personally I would use Joda Time:
Joda Time is a much better date and time API than the built-in one, but that would work too:
I wouldn’t use the (deprecated)
Dateconstructor though. For one thing, it doesn’t do what you appear to think it does… this:constructs a value representing the 2nd of February in the year 3912…
This won’t be a problem if you’re fetching the
Datefrom the database, but obviously it will affect unit testing. You should really avoid all the deprecated members ofDate– they’re deprecated for good reason.