Re: Set the local time
From: Drunkalot (r_luceac_at_hotmail.com)
Date: 12/16/04
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Is this thread safe?"
- Previous message: slamb_at_cognex.com: "DomainUpDown key input"
- In reply to: Anders Norås [MCAD]: "Re: Set the local time"
- Next in thread: Drunkalot: "Re: Set the local time"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 16 Dec 2004 18:05:33 -0200
Hi, thanks for the program...
Where can I find information about these function that are in windows dll???
"Anders Norås [MCAD]" <anders.noras@objectware.no> wrote in message
news:Ot8xwDw4EHA.208@TK2MSFTNGP12.phx.gbl...
> > How can I set the system time using a DateTime object???
> You can't set the local time with the DateTime structure, but you can do
it
> with the SetSystemTime method in kernel32.dll via PInvoke. The
SetSystemTime
> method accepts a SystemTime structure as its parameter. Populate this
> structure with the corresponding members of the DateTime structure.
>
> public class MyClass
> {
> public static void Main()
> {
> DateTime dt=DateTime.Now;
> SystemTime st=new SystemTime();
> st.Year=Convert.ToUInt16(dt.Year);
> st.Hour=Convert.ToUInt16(dt.Hour-1);
> SetSystemTime(ref st);
> }
>
> [DllImport("kernel32.dll")]
> public static extern int SetSystemTime(ref SystemTime systemTime);
> }
> [StructLayout(LayoutKind.Sequential)]
> public struct SystemTime {
> public System.UInt16 Year;
> public System.UInt16 Month;
> public System.UInt16 DayOfWeek;
> public System.UInt16 Day;
> public System.UInt16 Hour;
> public System.UInt16 Minute;
> public System.UInt16 Second;
> public System.UInt16 Millisecond;
> }
>
> Anders Norås
> http://dotnetjunkies.com/weblog/anoras/
>
>
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Is this thread safe?"
- Previous message: slamb_at_cognex.com: "DomainUpDown key input"
- In reply to: Anders Norås [MCAD]: "Re: Set the local time"
- Next in thread: Drunkalot: "Re: Set the local time"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|