39

I have a warning when running React Native on an Android device:

Debugger and device times had drifted by more than 60s. Please correct this by running adb shell "date `date +%m%d%H%M%Y.%S`" on your debugger machine

But when I run the command as suggested above, I get and operation not permitted error:

date: cannot set date: Operation not permitted

I already tried with sudo, still got same result:

sudo adb shell "date `date +%m%d%H%M%Y.%S`"
vun
  • 1,251
  • 1
  • 14
  • 17

8 Answers8

39

Inside the emulator goto Settings > Date & Time

  1. Deselect Automatic timezone.
  2. Adjust your timezone manually.
  3. Deselect automatic date & time and set correct time
atinder
  • 2,080
  • 13
  • 15
30

Deselecting automatic time and time zone did not work for me. Instead, I did adb shell su root date $(date +%m%d%H%M%Y.%S).

Adding "su root" is the solution to the "Operation not permitted" error.

Note that this is not equivalent to executing adb shell first and then su root date $(date +%m%d%H%M%Y.%S) (in this case $(date +%m%d%H%M%Y.%S) returns the emulator time, which is not correct, so even though the command succeeds, it does not fix the problem).

Andrii Chernenko
  • 9,873
  • 7
  • 71
  • 89
7

If your phone can run adb as root you can use the following commands:

>>> adb root
restarting adbd as root

>>> adb shell "date `date +%m%d%H%M%Y.%S`"       
Mon Aug 26 21:04:24 +0430 201
hamidfzm
  • 4,595
  • 8
  • 48
  • 80
6

I had this problem in real android device, I had a time difference between the pc and the mobile higher than 60 second. I solve the issue just by putting them on same time

  • 1
    Definitely a good idea to sync the clocks of the Android device and your computer's OS. Thank you, @Radhouane! – tonkatata Jun 06 '19 at 18:40
3

I had this problem and solved it by enabling 'set time automatically' in windows 10 Time and Language settings. also I enabled automatic date & time in my android phone.

Sinapcs
  • 2,495
  • 1
  • 20
  • 23
1

The shell command seems not to work anymore. My solution is just re-starting the emulator. After restart, The date-time will be synced again. I think that the problem is because the emulator is booted from a snapshot. This kind of boot doesn't cause the time calculation incorrect.

CodeMobiles
  • 91
  • 2
  • 2
0

I saw this problem last week, in my case i tried:

adb root
adb shell "date `date +%m%d%H%M%Y.%S`"

Then it's worked. Remember open the ADV first.

Nak
  • 251
  • 1
  • 6
0

After manually setting the emulator time correctly to match my MacBook's time, this issue however persists anytime, I leave the system inactive.

To deal with it, I simply restarted the emulator, but made sure the "Set time automatically" is toggled on. This would reset the time again to match correctly, without the need for a manual setting.

Okpo
  • 375
  • 4
  • 9