Click here to Skip to main content
16,007,779 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: C# and VC.net Pin
toxcct4-Aug-05 1:51
toxcct4-Aug-05 1:51 
GeneralRe: C# and VC.net Pin
4-Aug-05 21:20
suss4-Aug-05 21:20 
GeneralRe: C# and VC.net Pin
Christian Graus4-Aug-05 19:48
protectorChristian Graus4-Aug-05 19:48 
GeneralRegular Expression Pin
Ali Sajadian3-Aug-05 22:26
Ali Sajadian3-Aug-05 22:26 
GeneralRe: Regular Expression Pin
Christian Graus4-Aug-05 19:50
protectorChristian Graus4-Aug-05 19:50 
GeneralRe: Regular Expression Pin
Ali Sajadian6-Aug-05 22:25
Ali Sajadian6-Aug-05 22:25 
GeneralRe: Regular Expression Pin
Christian Graus7-Aug-05 13:34
protectorChristian Graus7-Aug-05 13:34 
GeneralConverting Server to Local Time Pin
Anonymous3-Aug-05 8:33
Anonymous3-Aug-05 8:33 
Hi all,

I need to update client machines with the correct time if it is inaccurate. The server I'm using will always have the correct time so I'll be using that as the source of correct time. The code below works most of the time but is an an hour off sometimes (daylightsavings time).

For example, If I change the date on a local to machine to Jan 2005, my code will update the time an hour ahead of where it should be. Any help would be appreciated.

Thanks,Paul

Code is below

using System;
using System.Runtime.InteropServices;

public void UpdateTime(DateTime ServerTime)
{
TimeZone localZone = TimeZone.CurrentTimeZone;
DateTime localTime = localZone.ToLocalTime(ServerTime);
TimeSpan localOffset = localZone.GetUtcOffset(localTime );
ServerTime = ServerTime.Add(localOffset);
SetTime(ServerTime);
}

[StructLayoutAttribute(LayoutKind.Sequential)]
private struct SYSTEMTIME
{
public short year;
public short month;
public short dayOfWeek;
public short day;
public short hour;
public short minute;
public short second;
public short milliseconds;
}

[DllImport("kernel32.dll")]
static extern bool SetLocalTime(ref SYSTEMTIME time);

private void SetTime(DateTime NewTime)
{
SYSTEMTIME st;
st.year = (short)NewTime.Year;
st.month = (short)NewTime.Month;
st.dayOfWeek = (short)NewTime.DayOfWeek;
st.day = (short)NewTime.Day;
st.hour = (short)NewTime.Hour;
st.minute = (short)NewTime.Minute;
st.second = (short)NewTime.Second;
st.milliseconds = (short)NewTime.Millisecond;
SetLocalTime(ref st);
}
GeneralRe: Converting Server to Local Time Pin
Mike Dimmick4-Aug-05 0:41
Mike Dimmick4-Aug-05 0:41 
GeneralRe: Converting Server to Local Time Pin
Anonymous5-Aug-05 2:57
Anonymous5-Aug-05 2:57 
GeneralGC Heap and PerfMon Pin
S. Senthil Kumar3-Aug-05 7:50
S. Senthil Kumar3-Aug-05 7:50 
GeneralWeb service async call from server to client Pin
NarayanVl3-Aug-05 3:33
NarayanVl3-Aug-05 3:33 
GeneralRe: Web service async call from server to client Pin
Carl Mercier3-Aug-05 15:09
Carl Mercier3-Aug-05 15:09 
Question.resX files question?? Pin
richiemac2-Aug-05 23:20
richiemac2-Aug-05 23:20 
QuestionNOT expression in Regex? Pin
dy131-Aug-05 10:26
dy131-Aug-05 10:26 
AnswerRe: NOT expression in Regex? Pin
Christian Graus1-Aug-05 12:12
protectorChristian Graus1-Aug-05 12:12 
QuestionSocks Tunneling? Pin
Hadi Fakhreddine1-Aug-05 7:09
Hadi Fakhreddine1-Aug-05 7:09 
AnswerRe: Socks Tunneling? Pin
David Leston3-Aug-05 19:16
David Leston3-Aug-05 19:16 
GeneralRe: Socks Tunneling? Pin
Hadi Fakhreddine4-Aug-05 1:50
Hadi Fakhreddine4-Aug-05 1:50 
GeneralRe: Socks Tunneling? Pin
David Leston4-Aug-05 16:48
David Leston4-Aug-05 16:48 
GeneralRe: Socks Tunneling? Pin
Hadi Fakhreddine4-Aug-05 19:18
Hadi Fakhreddine4-Aug-05 19:18 
QuestionConfig file for dll. Is it possible? Pin
ekacho1-Aug-05 3:14
ekacho1-Aug-05 3:14 
AnswerRe: Config file for dll. Is it possible? Pin
Mike Dimmick1-Aug-05 3:27
Mike Dimmick1-Aug-05 3:27 
GeneralRe: Config file for dll. Is it possible? Pin
ekacho1-Aug-05 3:48
ekacho1-Aug-05 3:48 
AnswerRe: Config file for dll. Is it possible? Pin
Dan Neely1-Aug-05 3:38
Dan Neely1-Aug-05 3:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.