Configuring Time and TimeZone...

Hi everybody,
      What is difference between a local time and a system time, Correct if I am wrong, system time is time of the system server where your computer is connected. So, if I would change system time I need to change the tme on the server. Right
     How would you set(change the local time programatically Also, using DateTime.UtcNow is to get system time How to change the system time programatically  How to get and set(change) Time Zone The system is a remote server say in different country. How to change and view this time

     The situation is this, if the application is to be used by say user from another country, they have their own local time and Time Zone Info, and their own system (server) time. I like these to be configurable. I know that to change timezone I need a class and method inside the System.Globalization. Can you help narrow it down or pinpoint it for setting and getting time zone Also, how to get a list of Time Zone to be displayed in a Combo Box Is there a method for this

Using DateTime.UtcNow is for local time no matter where country is after setting the timezone.

 


denpsia



Answer this question

Configuring Time and TimeZone...

  • Markish

    Thanks for reply james. Is there problem setting the system time you can change it back, right Is it the time clock on CPU

    I like to find replacements for this api functions of CE.

    [DllImport("coredll.dll", SetLastError=true)]
    public static extern int SetLocalTime (ref SystemTime lpSystemTime);

    [DllImport("coredll.dll", SetLastError=true)]
    public static extern bool SetSystemTime (ref SystemTime lpSystemTime);

    [DllImport("coredll.dll", SetLastError=true)]
    public static extern bool SetTimeZoneInformation (ref TimeZoneInformation lpTimeZoneInformation);

    [DllImport("coredll.dll", SetLastError=true)]
    public static extern void GetTimeZoneInformation(ref TimeZoneInformation lpTimeZoneInformation);

    [DllImport("coredll.dll", EntryPoint="GetSystemTime", SetLastError=true)]
    public static extern void GetSystemTime(ref SystemTime lpSystemTime);

    I used this api function SetSystemTime() of Kernel32.dll and it does not change time in my computer. Anybody knows how to fixed this

    [code]
    private void SetLocalTime(DateTime dtNew)
    {
        int dw = -1;
        SYSTEMTIME st = new SYSTEMTIME();
        st.wDay = dtNew.Day;
       
        if (dtNew.DayOfWeek == DayOfWeek.Sunday )
              dw = 0;
        else if (dtNew.DayOfWeek == DayOfWeek.Monday)
              dw = 1;
        else if (dtNew.DayOfWeek == DayOfWeek.Tuesday )
              dw = 2;
        else if (dtNew.DayOfWeek == DayOfWeek.Wednesday )
              dw = 3;
        else if (dtNew.DayOfWeek == DayOfWeek.Thursday )
              dw = 4;
        else if (dtNew.DayOfWeek == DayOfWeek.Friday )
              dw = 5;
        else if (dtNew.DayOfWeek == DayOfWeek.Saturday )
              dw = 6;
       
        st.wDayOfWeek = dw;
        st.wHour = dtNew.Hour;
        st.wMinute = dtNew.Minute;
        st.wSecond = dtNew.Second;
        st.wMonth = dtNew.Month;
        st.wYear = dtNew.Year;

        uint uRes = SetSystemTime(ref st); \\ returns 0

        if (uRes <= 0)
            MessageBox.Show("Unable to change Local time.");
    }
    [/code]

    How about changing remote server time How to do that  

    den2005


  • Youpas

    System time is the time on the system clock. Local time is the current time in your time zone adjusted for daylight savings time, if necessary. Windows will adjust system time when local time changes due to some event such as daylight savings time comes into effect or changing timezones. In order to modify your time, you need admin privileges (specifically the SeSystemtimePrivilege). Unless you're writing a time synchronization program or something similar, I wouldn't recommend changing the user's system clock, even if they have admin privileges.

  • RLewis

    *Another Update*

    I have succesfully change local pc time. I used SetLocalTime() of Kernel32.dll api. What is the diffrence bteween SetLocalTime() and SetSystemTime() They change the same local pc time. Right Is there anyone had idea how to change time of remote server from windows application I am using ras connection(vpn) to connect to remote server.


    denpsia



  • Configuring Time and TimeZone...