Solved

Setting Daylight Savings Flag

Posted on 2002-03-13
5
296 Views
Last Modified: 2008-02-01
I have some code to set the time & timezone on my machine.  To do this I use the SetLocalTime and SetTimezoneInformation methods.  What I can't seem to do is find a way to set the daylight savings flag on or off.  Can someone please let me know how to do this?  I'm guessing its just a matter of setting the correct information in the SYSTEMTIME struct I use when calling SetTimezoneInformation?
0
Comment
Question by:jpick
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Nick75 earned 50 total points
ID: 6861324
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

void main( void )
{
   if( _putenv( "TZ=EST5EDT" ) == -1 )
   {
      printf( "Unable to set TZ\n" );
      exit( 1 );
   }
   else
   {
      _tzset();
      printf( "_daylight = %d\n", _daylight );
      printf( "_timezone = %ld\n", _timezone );
      printf( "_tzname[0] = %s\n", _tzname[0] );
   }
   exit( 0 );
}
0
 

Author Comment

by:jpick
ID: 6862920
Thanks Nick75, I've seen that in the documentation(msdn).  The trouble is how do you know the 3 letter code for all the timezones, not just the ones in the US?  So if I live in Europe somewhere, how would I turn on/off daylight savings?
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7036228
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,

** Mindphaser - Community Support Moderator **

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.
0
 

Author Comment

by:jpick
ID: 7037441
Although this is not the answer I was looking for, I will give nick the points.
0
 
LVL 1

Expert Comment

by:Nick75
ID: 7037544
Have you played with the Bias member of TIME_ZONE_INFORMATION?

I'd assume "Coordinated Universal Time (UTC)" to mean GMT.  You may then choose to have an enumerated type or map<string,LONG> for various timezones around the world.  If you double click the clock on the Windows toolbar that'll get you started with a few offsets.  I won't guarantee that this is a full list - I'm sure I remember the timezone being off by 15 minutes somewhere - though I could be wrong - I'm sure they would have complained to MS... (but then, hasn't everybody :-) )
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question