SetSystemTime

M

MDB

Hello all, I am having problems with SetSystemTime. For some reason, my
ppc2003 device is not adjusting for DST (time behind by one hour). Here is
how I am setting it with the UTC time being passed to the function, should I
be doing this differently?

[DllImport("coredll.dll")]
private extern static bool SetSystemTime(ref SYSTEMTIME lpSystemTime);

public static void SyncSystemTime(string strDateTime)
{
try
{
// Set the clock ahead one hour
SYSTEMTIME st = new SYSTEMTIME();
DateTime temp = Convert.ToDateTime(strDateTime);
st.wYear = (ushort)temp.Year;
st.wMonth = (ushort)temp.Month;
st.wDayOfWeek = (ushort)temp.DayOfWeek;
st.wDay = (ushort)temp.Day;
st.wHour = (ushort)temp.Hour;
st.wMinute = (ushort)temp.Minute;
st.wSecond = (ushort)temp.Second;
st.wMilliseconds = (ushort)temp.Millisecond;
if(!SetSystemTime(ref st))
{
myapp.Classes.Errors.LogNonExceptionError("Time not synced - " +
strDateTime,"Functions","SyncSystemTime","");
}

}
catch(Exception exc)
{
myapp.Classes.Errors.LogException(exc,"Functions","SyncSystemTime","");
}
}
 
P

Paul G. Tobey [eMVP]

SetSystemTime() is setting the GMT time, *not* the local time of the device!
SetLocalTime() would be used to set the local time that the device
uses/displays.

If you are saying that, despite setting the correct DST value, the local
time reported is wrong, then I'd guess that you haven't set the timezone and
DST adjustment flag correctly. Check the Control Panel.

Paul T.
 
M

MDB

Yes I know it is the GMT/UTC and yes the timezone is set correctly. What I
have not been able to check is the DST adjustment flag. Where is this found
in PPC2003? I can not seem to find it.


Paul G. Tobey said:
SetSystemTime() is setting the GMT time, *not* the local time of the
device! SetLocalTime() would be used to set the local time that the device
uses/displays.

If you are saying that, despite setting the correct DST value, the local
time reported is wrong, then I'd guess that you haven't set the timezone
and DST adjustment flag correctly. Check the Control Panel.

Paul T.

MDB said:
Hello all, I am having problems with SetSystemTime. For some reason, my
ppc2003 device is not adjusting for DST (time behind by one hour). Here
is how I am setting it with the UTC time being passed to the function,
should I be doing this differently?

[DllImport("coredll.dll")]
private extern static bool SetSystemTime(ref SYSTEMTIME lpSystemTime);

public static void SyncSystemTime(string strDateTime)
{
try
{
// Set the clock ahead one hour
SYSTEMTIME st = new SYSTEMTIME();
DateTime temp = Convert.ToDateTime(strDateTime);
st.wYear = (ushort)temp.Year;
st.wMonth = (ushort)temp.Month;
st.wDayOfWeek = (ushort)temp.DayOfWeek;
st.wDay = (ushort)temp.Day;
st.wHour = (ushort)temp.Hour;
st.wMinute = (ushort)temp.Minute;
st.wSecond = (ushort)temp.Second;
st.wMilliseconds = (ushort)temp.Millisecond;
if(!SetSystemTime(ref st))
{
myapp.Classes.Errors.LogNonExceptionError("Time not synced - " +
strDateTime,"Functions","SyncSystemTime","");
}

}
catch(Exception exc)
{
myapp.Classes.Errors.LogException(exc,"Functions","SyncSystemTime","");
}
}
 
S

Sergey Bogdanov

To check if it turn on (it should be on) see registry value:
HKLM/Software/Microsoft/Clock/HomeDST


--
Sergey Bogdanov
http://www.sergeybogdanov.com

Yes I know it is the GMT/UTC and yes the timezone is set correctly. What I
have not been able to check is the DST adjustment flag. Where is this found
in PPC2003? I can not seem to find it.


SetSystemTime() is setting the GMT time, *not* the local time of the
device! SetLocalTime() would be used to set the local time that the device
uses/displays.

If you are saying that, despite setting the correct DST value, the local
time reported is wrong, then I'd guess that you haven't set the timezone
and DST adjustment flag correctly. Check the Control Panel.

Paul T.

Hello all, I am having problems with SetSystemTime. For some reason, my
ppc2003 device is not adjusting for DST (time behind by one hour). Here
is how I am setting it with the UTC time being passed to the function,
should I be doing this differently?

[DllImport("coredll.dll")]
private extern static bool SetSystemTime(ref SYSTEMTIME lpSystemTime);

public static void SyncSystemTime(string strDateTime)
{
try
{
// Set the clock ahead one hour
SYSTEMTIME st = new SYSTEMTIME();
DateTime temp = Convert.ToDateTime(strDateTime);
st.wYear = (ushort)temp.Year;
st.wMonth = (ushort)temp.Month;
st.wDayOfWeek = (ushort)temp.DayOfWeek;
st.wDay = (ushort)temp.Day;
st.wHour = (ushort)temp.Hour;
st.wMinute = (ushort)temp.Minute;
st.wSecond = (ushort)temp.Second;
st.wMilliseconds = (ushort)temp.Millisecond;
if(!SetSystemTime(ref st))
{
myapp.Classes.Errors.LogNonExceptionError("Time not synced - " +
strDateTime,"Functions","SyncSystemTime","");
}

}
catch(Exception exc)
{
myapp.Classes.Errors.LogException(exc,"Functions","SyncSystemTime","");
}
}
 
P

Paul G. Tobey [eMVP]

You can force it on or off by calling SetDaylightTime().

Paul T.

Sergey Bogdanov said:
To check if it turn on (it should be on) see registry value:
HKLM/Software/Microsoft/Clock/HomeDST


--
Sergey Bogdanov
http://www.sergeybogdanov.com

Yes I know it is the GMT/UTC and yes the timezone is set correctly. What
I have not been able to check is the DST adjustment flag. Where is this
found in PPC2003? I can not seem to find it.


SetSystemTime() is setting the GMT time, *not* the local time of the
device! SetLocalTime() would be used to set the local time that the
device uses/displays.

If you are saying that, despite setting the correct DST value, the local
time reported is wrong, then I'd guess that you haven't set the timezone
and DST adjustment flag correctly. Check the Control Panel.

Paul T.

"MDB" <nospam> wrote in message

Hello all, I am having problems with SetSystemTime. For some reason, my
ppc2003 device is not adjusting for DST (time behind by one hour). Here
is how I am setting it with the UTC time being passed to the function,
should I be doing this differently?

[DllImport("coredll.dll")]
private extern static bool SetSystemTime(ref SYSTEMTIME lpSystemTime);

public static void SyncSystemTime(string strDateTime)
{
try
{
// Set the clock ahead one hour
SYSTEMTIME st = new SYSTEMTIME();
DateTime temp = Convert.ToDateTime(strDateTime);
st.wYear = (ushort)temp.Year;
st.wMonth = (ushort)temp.Month;
st.wDayOfWeek = (ushort)temp.DayOfWeek;
st.wDay = (ushort)temp.Day;
st.wHour = (ushort)temp.Hour;
st.wMinute = (ushort)temp.Minute;
st.wSecond = (ushort)temp.Second;
st.wMilliseconds = (ushort)temp.Millisecond;
if(!SetSystemTime(ref st))
{
myapp.Classes.Errors.LogNonExceptionError("Time not synced - " +
strDateTime,"Functions","SyncSystemTime","");
}

}
catch(Exception exc)
{
myapp.Classes.Errors.LogException(exc,"Functions","SyncSystemTime","");
}
}
 
M

MDB

Thanks


Paul G. Tobey said:
You can force it on or off by calling SetDaylightTime().

Paul T.

Sergey Bogdanov said:
To check if it turn on (it should be on) see registry value:
HKLM/Software/Microsoft/Clock/HomeDST


--
Sergey Bogdanov
http://www.sergeybogdanov.com

Yes I know it is the GMT/UTC and yes the timezone is set correctly.
What I have not been able to check is the DST adjustment flag. Where is
this found in PPC2003? I can not seem to find it.


"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
wrote in message
SetSystemTime() is setting the GMT time, *not* the local time of the
device! SetLocalTime() would be used to set the local time that the
device uses/displays.

If you are saying that, despite setting the correct DST value, the local
time reported is wrong, then I'd guess that you haven't set the timezone
and DST adjustment flag correctly. Check the Control Panel.

Paul T.

"MDB" <nospam> wrote in message

Hello all, I am having problems with SetSystemTime. For some reason,
my ppc2003 device is not adjusting for DST (time behind by one hour).
Here is how I am setting it with the UTC time being passed to the
function, should I be doing this differently?

[DllImport("coredll.dll")]
private extern static bool SetSystemTime(ref SYSTEMTIME lpSystemTime);

public static void SyncSystemTime(string strDateTime)
{
try
{
// Set the clock ahead one hour
SYSTEMTIME st = new SYSTEMTIME();
DateTime temp = Convert.ToDateTime(strDateTime);
st.wYear = (ushort)temp.Year;
st.wMonth = (ushort)temp.Month;
st.wDayOfWeek = (ushort)temp.DayOfWeek;
st.wDay = (ushort)temp.Day;
st.wHour = (ushort)temp.Hour;
st.wMinute = (ushort)temp.Minute;
st.wSecond = (ushort)temp.Second;
st.wMilliseconds = (ushort)temp.Millisecond;
if(!SetSystemTime(ref st))
{
myapp.Classes.Errors.LogNonExceptionError("Time not synced - " +
strDateTime,"Functions","SyncSystemTime","");
}

}
catch(Exception exc)
{
myapp.Classes.Errors.LogException(exc,"Functions","SyncSystemTime","");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top