CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2004
    Posts
    30

    figuring out all this timezone stuff

    Hi,

    I'm trying to write a sample app. to find out the time on a computer and convert it to mountain time.

    I'm new to this stuff, and I found out some stuff on _ftime which gives you the timezone that is the "Difference in minutes, moving westward, between UTC and local time. The value of timezone is set from the value of the global variable _timezone (see _tzset)."

    I'm not sure what UTC is and if this is the write method I should be using for what I'm doing.

    Can someone please suggest to me what I can do or is there some tutorial or sample code out there which has something similar to what i'm doing here?

    Thank you

    Shannon

  2. #2
    Join Date
    Jan 2004
    Location
    Altos
    Posts
    168

    Talking

    try this maybe this is what u r looking for if not tell
    Code:
    CString nm;
    	TIME_ZONE_INFORMATION tmzninf;
    	GetTimeZoneInformation(&tmzninf);
    	nm = tmzninf.StandardName;
            AfxMessageBox(nm);
    The above code will give u ur timezone is this wat u wanted r did I misread
    For getting the time try this
    Code:
    CTime t( 1999, 3, 19, 22, 15, 0 ); 
    time_t osBinaryTime = t.GetTime();
    printf( "time_t = %ld\n", osBinaryTime );
    is this wat u want if not tell me
    "I came"
    "I saw"
    "I conquered"

  3. #3
    Join Date
    Jan 2004
    Posts
    30
    Great, thank you Cyber Bandit I'll try this out!

    Would it be proper programming to have a big switch statement where the cases are all the possible timezones each having a predefined off-set in hours to the mountain time?

    i just want to make sure that there isn't some sdk method that will take the current time and can adjust it to a specified timezone (in my case, mountain time).

    thanks!

  4. #4
    Join Date
    Jan 2004
    Location
    Altos
    Posts
    168

    Talking

    well I think what u r looking for is SetTimeZoneInformation(). Hope this solves ur problem u can get more info bout that in MSDN just look for it
    "I came"
    "I saw"
    "I conquered"

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Is mountain time the time zone for you and is your system set to that timezone? Will all systems using this software have their timezones set to mountain time?

    Yes, UTC is very appropriate for use in this manner. You can use a function that gets the current UTC and then use a function that converts UTC to the time appropriate for your system. The C runtime functions can do that. In that way, the software will be flexible enough that it is likely to work in any timezone.

    However if you need to convert to mountan time but mountain time is not the local time, then things are more complicated.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #6
    Join Date
    Jan 2004
    Posts
    30
    Hi Sam, actually I have an app. that basically reads from a file that contains times in mountain time. Potentially this app may sit somewhere on a machine in a different timezone. The reason why I would like to figure out how to convert to mountain time, (not change it) is because I want to take the time on the person's machine (whatever timezone it is) and then see what it is in mountain time so that the time in the file makes sense.

    I guess the thing i would be using is GetTimeZoneInformation and use the bias and also bring in the bias from the mountain time into the equation.

    Thanks

  7. #7
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Then I will assume you have it solved.

    I did spend some time figuring out timezone information but it has been a while so it is good that your solution is easy enough that I don't need to attempt remembering or searching.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  8. #8
    Join Date
    Jan 2004
    Posts
    30
    Hi, I just have another question here.

    Under the "date/time properties", I guess there is the potential for the user to check/uncheck the option "Automatically adjust clock for daylight savings changes"

    Is there an api to determine if this option is checked or not?

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured