newbie could somone please tell me why this code does not work

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: darren (no email)
Date: 02/08/04


Date: Sun, 08 Feb 2004 17:55:57 +0000

Hi i have alterd some code that changed the system time so it changes
the date could you olease tell me why it does not work

using System;
using System.Runtime.InteropServices;

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

                public class MyTimeAdjuster
                {
                        [DllImport("kernel32.dll")]
                        public static extern bool GetSystemTime(ref
SystemTime systemTime);
                        [DllImport("kernel32.dll")]
                        public static extern bool SetSystemTime(ref
SystemTime systemTime);

                        void SetNewTime(short d, short m, short y)
                        {
                                SystemTime st = new SystemTime();
                                GetSystemTime(ref st);
                                st.wDay = d;
                                st.wMonth = m;
                                st.wYear = y;
                                SetSystemTime(ref st);
                        }

                        public static void Main(string[] args)
                        {
                                MyTimeAdjuster myTime = new
MyTimeAdjuster();
                                myTime.SetNewTime(1,12,2002);
                        }
                }

        



Relevant Pages

  • Should programs handle system time jumps?
    ... handle jumps in the system time. ... The jumps occur when, for demonstrating ... The problem is that certain threads that poll things wait between polls for ... If, in that waitcycle, the systemtime is rewound by a year, ...
    (comp.programming)
  • Re: Set the local time
    ... >> How can I set the system time using a DateTime object??? ... > with the SetSystemTime method in kernel32.dll via PInvoke. ... > method accepts a SystemTime structure as its parameter. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Set the local time
    ... > How can I set the system time using a DateTime object??? ... You can't set the local time with the DateTime structure, ... with the SetSystemTime method in kernel32.dll via PInvoke. ... method accepts a SystemTime structure as its parameter. ...
    (microsoft.public.dotnet.languages.csharp)