473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Converting Server to Local Time

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);
}

Aug 3 '05 #1
0 1417

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Elie Grouchko | last post by:
Hi All 1. I need to convert the local-time of the server on which I run my website to UTC and I don't want to rely on the server local time and timezone (i.e. I don't want to hardcode the...
6
by: Jim Davis | last post by:
Before I reinvent the wheel I thought I'd ask: anybody got a code snippet that will convert the common ISO8601 date formats to a JS date? By "common" I mean at the least ones described in this...
8
by: Uttam | last post by:
Hello, I am currently in the process of developing an application in a pure desktop world using Access 2000. I am intending to convert this pure desktop application into a Client Server...
14
by: D | last post by:
Hey guys- not sure where this post fits in, so I cc'd a few other groups as well- hope you dont mind... I have someone creating a database for me in Access 2000 (or is it called XP?). When it's...
0
by: pdunc | last post by:
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. ...
29
by: Jan | last post by:
Hi: I have an Access database that's been running (in one form or another) for a couple of different clients for a few years. Now a new client has requested that it be implemented with a SQL...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
3
by: deepeshn | last post by:
Hi people, I have a function which will receive 2 parameters:the date field in GMT time and the user's time zone. I have to return a datetime field in the user's time. the thing is the server...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.