I have a requirement to change System s date time from UWP app. I am trying below methods but it is not working. Same methods works if I run from Console App.
[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 SYSTEMTIME GetSystemTime();
public void ChangeDateTime()
{
SYSTEMTIME a = GetSystemTime();
SYSTEMTIME st = new SYSTEMTIME();
st.wYear = (short)a.wYear;
st.wMonth = (short)a.wMonth;
st.wDay = (short)a.wDay;
st.wHour = (short)a.wHour;
st.wMinute = (short)(a.wMinute + 5);
st.wSecond = (short)a.wSecond;
st.wMilliseconds = (short)a.wMilliseconds;
bool i = SetSystemTime(ref st);
}
SetSystemtime回报不实,日期没有生效。
我是否失踪了,或者有什么其他办法去做?