[APP/FIX] Date/Time 1970 bug workaround v2.2

Search This thread

dougiebee

Senior Member
Sep 21, 2007
71
127
Hope this helps someone. I got fairly sick of the date/time bug giving me error alerts upon reboot. This fix takes the RTC date/time and applies an offset specific to your own phone to set the correct date/time at startup. I have attached an APK to make life easy. It should also give the ability to have recovery use the files it creates to set the clock correctly on startup.

The app requires root. If running AOSP, your ROM must have initscript support.

The app has 3 functions:
  • Install offset only (for use with a compatible recovery, not used by the ROM)
  • Install offset and initscript (to correct ROM clock offset, also for use with a compatible recovery)
  • Uninstall (Remove /data/local/userinit.sh /data/media/rtc_offset and /sdcard/rtc_offset)

Feel free to include the app in your own ROMs, just give me credit :)

As of version 2.0, the script will create /data/media/rtc_offset which can be used by recovery to correct the date/time on boot. Note this will require the recovery to specifically support this correction.

Version 2.1 uses /system/bin/toolbox for compatibility across roms (rather than relying on whatever /system/bin/date points to)

Version 2.2 places the rtc_offset file both in /sdcard/rtc_offset and also in /data/media/rtc_offset if available. The initscript will use either file that is available. This is for possible compatibility with older phones that may not have /data/media, at the request of Phil3759

Special thanks to Atze001, sniperle and Phil3759.

Hope this helps, enjoy.
 

Attachments

  • Clock_Offset_Fix_1.0.apk
    265.9 KB · Views: 1,031
  • Clock_Offset_Fix_1.1.apk
    265.9 KB · Views: 372
  • Clock_Offset_Fix_2.0.apk
    266 KB · Views: 563
  • Clock_Offset_Fix_2.1.apk
    266 KB · Views: 731
  • Clock_Offset_Fix_2.2.apk
    266.1 KB · Views: 5,742
Last edited:

murdoch1

Senior Member
Jan 16, 2010
838
202
Hope this helps someone. I got fairly sick of the date/time bug giving me error alerts upon reboot. My solution was to get the modification date of the /data/system directory and set that as the current date at boot time. Not great, but better than 1970. This or something similar may be posted elsewhere but I haven't seen it.

I'm running CM11 - not sure whether this works on other AOSP ROMS.

1) Create a file named 01datehack with the following content:

Code:
#!/system/bin/sh
olddate=`ls -ld /data/system | awk '{print $4, $5}' | sed -e 's/-//g' -e 's/ /./g' -e 's/://g' -e 's/$/00/g'`
date -s $olddate

Then run the following commands:
Code:
adb root
adb shell "mkdir -p /data/local/userinit.d"
adb push 01datehack /data/local/userinit.d
adb shell "chmod 755 /data/local/userinit.d/01datehack"

As it lives in /data it will survive flashing an update as long as you don't wipe. It's only a couple of fairly noddy linux commands, there's quite possibly a command line switch that would negate the need for all the SED'ing - also possibly a better directory/file to look at.

Hope this helps, enjoy.

I'm on the latest cm11 nightly. Tried your code but didn't make any difference. Phone still started up in February and then changed to today's date after network/WiFi started.
 

murdoch1

Senior Member
Jan 16, 2010
838
202
1970

What do you get from "adb shell ls -ld /data/system"? Have you enabled ADB root access in developer options?


Yes enabled ADB root access in Developer options. Running the command you provided results me with the following:-

drwxrwxr-x system system 2013-12-23 08:47 system

Cheers
 

Atze001

Senior Member
Apr 2, 2007
929
87
Berlin
You can try it. If it dont work you get an Installation error and nothing more happens.

If you get an Error please tell me i will fix it for CWM.
 
Last edited:
  • Like
Reactions: murdoch1

RieGo

Senior Member
Apr 1, 2010
361
463
  • Like
Reactions: madmax916sps

dougiebee

Senior Member
Sep 21, 2007
71
127
I now have a much better fix. It uses the RTC rather than relying on file timestamps. It's easy to implement, but creation of a flashable zip will not be straight forward.

I ran the following using ADB once the system was up and the date/time was correct:

Code:
expr $(date +%s) - $(cat /sys/class/rtc/rtc0/since_epoch)
Which gave me 1384422218 - which is "Thu Nov 14 09:43:38 GMT 2013" - the exact date/time I first powered on my phone after I got it.

So I edited my userinit file to read:
Code:
#!/system/bin/sh
realdate=$(expr 1384422218 + `cat /sys/class/rtc/rtc0/since_epoch` | awk '{print strftime("%Y%m%d.%H%M%S",$1)}')
date -s $realdate

This takes my hard-coded (device-specific) power-on time and adds the current RTC time since then to give me the correct date/time, much better than using the timestamp of a file or directory.

I'll update the OP if others confirm this works for them. Note: you need to replace 1384422218 with the number specific to your phone. Creating a flashable zip would be a bit of a challenge, as it would need to be device specific.
 
Last edited:

DerSpatz

Senior Member
Jun 12, 2012
100
61
Wouldn't it be possible to add a script to the flashable zip that determines the correct value and modifies the flashable file with the value before or after flashing?

PS: I don't know anything about this stuff... ;)
 

murdoch1

Senior Member
Jan 16, 2010
838
202
I now have a much better fix. It uses the RTC rather than relying on file timestamps. It's easy to implement, but creation of a flashable zip will not be straight forward.

I ran the following using ADB once the system was up and the date/time was correct:

Code:
expr $(date +%s) - $(cat /sys/class/rtc/rtc0/since_epoch)
Which gave me 1384422218 - which is "Thu Nov 14 09:43:38 GMT 2013" - the exact date/time I first powered on my phone after I got it.

So I edited my userinit file to read:
Code:
#!/system/bin/sh
realdate=$(expr 1384422218 + `cat /sys/class/rtc/rtc0/since_epoch` | awk '{print strftime("%Y%m%d.%H%M%S",$1)}')
date -s $realdate

This takes my hard-coded (device-specific) power-on time and adds the current RTC time since then to give me the correct date/time, much better than using the timestamp of a file or directory.

I'll update the OP if others confirm this works for them. Note: you need to replace 1384422218 with the number specific to your phone. Creating a flashable zip would be a bit of a challenge, as it would need to be device specific.

Just applied your new version. Works a treat. As you say its better than basing the date on a file timestamp. I basically used the flash zip and amended the unserinit.sh script with the code generated on my device.

All done.

Cheers again.:D:D:D:D
 
  • Like
Reactions: dougiebee

jlee08517

Senior Member
Aug 30, 2012
615
163
I now have a much better fix. It uses the RTC rather than relying on file timestamps. It's easy to implement, but creation of a flashable zip will not be straight forward.

I ran the following using ADB once the system was up and the date/time was correct:

Code:
expr $(date +%s) - $(cat /sys/class/rtc/rtc0/since_epoch)
Which gave me 1384422218 - which is "Thu Nov 14 09:43:38 GMT 2013" - the exact date/time I first powered on my phone after I got it.

So I edited my userinit file to read:
Code:
#!/system/bin/sh
realdate=$(expr 1384422218 + `cat /sys/class/rtc/rtc0/since_epoch` | awk '{print strftime("%Y%m%d.%H%M%S",$1)}')
date -s $realdate

This takes my hard-coded (device-specific) power-on time and adds the current RTC time since then to give me the correct date/time, much better than using the timestamp of a file or directory.

I'll update the OP if others confirm this works for them. Note: you need to replace 1384422218 with the number specific to your phone. Creating a flashable zip would be a bit of a challenge, as it would need to be device specific.

Does this survive flashing or do I need to do this every time I flash?

Sent from my LG-VS980 using Tapatalk
 

Top Liked Posts

  • There are no posts matching your filters.
  • 67
    Hope this helps someone. I got fairly sick of the date/time bug giving me error alerts upon reboot. This fix takes the RTC date/time and applies an offset specific to your own phone to set the correct date/time at startup. I have attached an APK to make life easy. It should also give the ability to have recovery use the files it creates to set the clock correctly on startup.

    The app requires root. If running AOSP, your ROM must have initscript support.

    The app has 3 functions:
    • Install offset only (for use with a compatible recovery, not used by the ROM)
    • Install offset and initscript (to correct ROM clock offset, also for use with a compatible recovery)
    • Uninstall (Remove /data/local/userinit.sh /data/media/rtc_offset and /sdcard/rtc_offset)

    Feel free to include the app in your own ROMs, just give me credit :)

    As of version 2.0, the script will create /data/media/rtc_offset which can be used by recovery to correct the date/time on boot. Note this will require the recovery to specifically support this correction.

    Version 2.1 uses /system/bin/toolbox for compatibility across roms (rather than relying on whatever /system/bin/date points to)

    Version 2.2 places the rtc_offset file both in /sdcard/rtc_offset and also in /data/media/rtc_offset if available. The initscript will use either file that is available. This is for possible compatibility with older phones that may not have /data/media, at the request of Phil3759

    Special thanks to Atze001, sniperle and Phil3759.

    Hope this helps, enjoy.
    14
    Try this. I have made a flashable zip for TWRP

    http://xdaforums.com/showpost.php?p=48760802&postcount=13

    Its a userinit.sh script in data/local
    13
    I wrote a quick app to ease installation, I think this is about as straight forward as it could get. Requires root. As before, your ROM must have initscript support.

    The app has 3 functions:

    • Get Offset (Get the Clock Time offset, so you can create your own flashable zip)
    • Install (Install the fix in /data/local/userinit.sh)
    • Uninstall (Remove /data/local/userinit.sh)

    Can someone please test this? Works perfectly on my phone. I'll update the OP once I get confirmation from someone else.

    To test, remove any existing fix, make sure the time is correct, install, reboot.

    I'd like to add creation of a flashable zip, but that will have to wait till I have time.

    Thanks go to sniperle and Atze001 for the idea.
    10
    Here are the new Links for the flashable fix.

    This one ist with userinit.sh in data/local
    https://dl.dropboxusercontent.com/u/20033515/TimeDateFix/TimeDateFix_Local.zip

    and this ist the original with 01datehack in data/local/userinit.d
    https://dl.dropboxusercontent.com/u/20033515/TimeDateFix/TimeDateFix_org.zip
    7
    I now have a much better fix. It uses the RTC rather than relying on file timestamps. It's easy to implement, but creation of a flashable zip will not be straight forward.

    I ran the following using ADB once the system was up and the date/time was correct:

    Code:
    expr $(date +%s) - $(cat /sys/class/rtc/rtc0/since_epoch)
    Which gave me 1384422218 - which is "Thu Nov 14 09:43:38 GMT 2013" - the exact date/time I first powered on my phone after I got it.

    So I edited my userinit file to read:
    Code:
    #!/system/bin/sh
    realdate=$(expr 1384422218 + `cat /sys/class/rtc/rtc0/since_epoch` | awk '{print strftime("%Y%m%d.%H%M%S",$1)}')
    date -s $realdate

    This takes my hard-coded (device-specific) power-on time and adds the current RTC time since then to give me the correct date/time, much better than using the timestamp of a file or directory.

    I'll update the OP if others confirm this works for them. Note: you need to replace 1384422218 with the number specific to your phone. Creating a flashable zip would be a bit of a challenge, as it would need to be device specific.