Why toMillis () function returns -1 in java

In android, when executing the code snippet below, date3 returns -1

booking_year2 = 2038;
booking_month2 = 1;
booking_day2 = 17;
Time t = new Time();
t.set(booking_day2, booking_month2 - 1, booking_year2);
long date3 = t.toMillis(false);
//date3 returns 2147451300000 as expected

//But if we run with values:
booking_year2 = 2038;
booking_month2 = 1;
booking_day2 = 18;
//date3 returns -1

While the time object "t" was expecting a value in all conditions, the long value returned by toMillis () is -1. And also for all upper date values ​​after jan 19, 2038, the toMillis () function returns only -1, not the expected value.

I did not understand and did not find a suitable reason or solution for this. Please let me know if I am doing something wrong or there is another way to find millisecond values ​​after this date.

+4
source share
2 answers

year-2038-problem, android.text.format.Time ( android). UNIX. :

" struct tm struct tm .

, ++ - , UNIX-. 32 , 2038 . , , . Android:

37653: android.text.format.Time 2038

+2

Joda-Time, .

DateTime dateTime = new DateTime( 2099, 1, 2, 3, 4, 5, DateTimeZone.UTC );
long millis = dateTime.getMillis();

...

System.out.println( "dateTime: " + dateTime );
System.out.println( "millis: " + millis );

...

dateTime: 2099-01-02T03:04:05.000Z
millis: 4071006245000
0

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


All Articles