Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting TimeZone of Java Calendar to device timezone?

Tags:

android

How can I construct a Calendar object using getInstance(TimeZone) to use the device's TimeZone?

like image 233
LuxuryMode Avatar asked Dec 05 '25 01:12

LuxuryMode


1 Answers

According to this issue, just using:

Calendar calendar = Calendar.getInstance();

will give you an instance in the user's default time zone (as per their settings). You can determine the time zone from the calendar with:

TimeZone zone = calendar.getTimeZone();

Other posts have suggested that using TimeZone.getDefault() does not give this user-default time zone - I don't know about that personally, but it's another option to look into.

like image 181
Jon Skeet Avatar answered Dec 06 '25 15:12

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!