3

I'm inserting a date to a database H2 in a Android application and when the date is bigger than January 19, 2038 (Unix year 2038 bug) the date that is saved to the database changes according the timezone of the android device.

Example: Date 2050-12-31

  • Timezone +2:00 El Cairo saves 2050-12-29 (ERROR)
  • Timezone +2:00 Amsterdam saves 2050-12-30 (ERROR)
  • Timezone +2:00 Brussels saves 2050-12-31 (OK)
  • Timezone of Japan saves 2050-12-31 (OK)
  • Timezone of China saves 2050-12-31 (OK)
  • Timezone of Azores saves 2050-12-31 (OK)

I suppose that the Linux kernel that uses android has the 2038 year bug but I don't understand the reason of in some cases it works ok and in others don't.

Any solution to this problem? Is safe use java.util.Date in Android?

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • 1
    How exactly do you insert and query the data - could you add the source code you use? What version of H2 and Android do you use? – Thomas Mueller Apr 12 '12 at 19:05
  • Android 4.0 and Android 3.2. In the two versions it fails. The version of H2 is 1.3.160. I have a jave.util.Date that debugging I see correctly, save it to the database and when I retrieve it the data changes in the some cases according to the timezone. I think that the problem is with android and the dates beyond 2038-1-19 –  Apr 16 '12 at 08:29
  • Android just got 64-bit support in Android 5 (Lollipop) in 2014 so there's no way to work around the year2038 problem at the time of this question without external libraries. Unlike Windows where 64-bit `time_t` was available in 32-bit OS since 2005, on Linux you need to use Linux 5.6 kernel in 2020 to get 64-bit `time_t` support in 32-bit mode: [How to use mktime64(), time64() and localtime64() function with 32-bit time library?](https://stackoverflow.com/q/57198602/995714) – phuclv Jun 08 '21 at 13:14

0 Answers0