Problems with the wrong time zone on Android

Now the right time zone for Moscow is UTC +3. But Android 4.4.4 knows only UTC +4for Moscow.

And java.util.Dateenter the wrong time:

Date now = new Date();    
Sat Nov 21 00:37:24 GMT+04:00 2015
1448051844024 in (milliseconds)

Using Joda org.joda.time

DateTime nowWithCorrect = new DateTime()
                              .withZone(DateTimeZone.forID("Europe/Moscow"));
2015-11-20T23:37:24.023+03:00
1448051844024 in (milliseconds)

But the problem is that the user (on devices with the wrong time zone) manually fixed the time on the device. And jodathey javagive the wrong time in milliseconds.

I get the time stamp of the web service and on the device I calculate different things according to local time. But local time is incorrect and gives incorrect results.

I want to check jodaboth javatime and manually to fix the time stamp.

: (now nowWithCorrect)? : differentTimeZone = 1, differentTimeHours = 1

+4
2

, Moscows offset-from-UTC +03:00 +04:00. . .

2011 +03:00 (DST) +04:00.

2011 , DST, +04:00 +03:00. . RT.com.

2014 . +03:00 DST ( +04:00).

tz

, , tz database ( Olson), . Java tz, , , tz. Joda-Time tz. , Android , Android.

, tz - .

Joda-Time Joda-Time . tz Joda-Time, , Joda-Time 2, . . Joda-Time, ; Android, Java -, .

Java tz. . , Java 8, .

, , tz. . .

UTC

- , , UTC. -, , , .. UTC. , Europe/Moscow, / .

Java 8 java.time. Instant UTC. ZoneId, ZonedDateTime, . Java 8 Android. , Android Java- java.time, .

Joda-Time UTC.

DateTime nowUtc = DateTime.now( DateTimeZone.UTC );

/ , , - UTC . . , .

.

DateTime nowMoscow = nowUtc.withZone( DateTimeZone.forID( "Europe/Moscow" ) );

tz Joda-Time , . , , . - Joda-Time tz. , , , , - -, .

--

, count-from- epoch.

Joda-Time, java.util.Date/.Calendar 1970 UTC. . , -- , , Android Date ( - tz).

, java.time count-from-epoch, (1970 UTC). Joda-Time getMillis, . java.util.Date getTime.

+1

joda-time ( IANA) Android:

long diff = DateTimeZone.getDefault().getOffset(yourTimeStapm) - TimeZone.getDefault().getOffset(yourTimeStapm);

joda-time, : https://gitlab.com/olekdia/common/utils/support-joda-time

0

Source: https://habr.com/ru/post/1616841/


All Articles