- Home /
How to set system time on android?
Hi, i need to set system time and date on android. I found a script, but it works only on Windows. Is there any possiblity to do this?
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetLocalTime(ref SYSTEMTIME st);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern void GetLocalTime(ref SYSTEMTIME st);
SYSTEMTIME ourDate = new SYSTEMTIME();
GetLocalTime(ref ourDate);
Console.WriteLine("{0}:{1}:{2}", ourDate.wHour, ourDate.wMinute, ourDate.wSecond);
ourDate.wHour = 10;
ourDate.wMinute = 10;
ourDate.wSecond = 34;
SetLocalTime(ref ourDate);
Console.ReadLine();
Answer by Yury-Habets · May 21, 2015 at 08:24 AM
The "script" you presented is just a translation of a native call to Windows API. I doubt it will work without admin privileges or even elevated privileges on latest Windows.
As for Android, the API to call could be http://developer.android.com/reference/android/os/SystemClock.html#setCurrentTimeMillis(long)
According to Google http://code.google.com/p/android/issues/detail?id=4581 ,
Hi, it is by design that applications can not change the time. There are many subtle aspects of security that can rely on the current time, such as certificate expiration, license management, etc. We do not want to allow third party applications to globally disrupt the system in this way.
This is highly likely that you cannot do it in Android without rooting the device.