Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

detect if date/time is daylight savings time

Posted on 2004-03-31
4
Medium Priority
?
485 Views
Last Modified: 2013-11-20
Hi,

Given the following datetime string "2004-03-30 13:09:28" I need to detect if it is PST or PDT?

Dalight Savings time:
Starts: First Sunday in April at 2 am local time
Ends: Last Sunday in October at 2 am local time

What I need to do is append PST or PDT accordingly.

Thanks,
Alex
0
Comment
Question by:astankovic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 2000 total points
ID: 10727902
int startday = 1;
int endday = 31;

COleDateTime startDST(2004, 4, startday, 2, 0, 0);
COleDateTime endDST(2004, 10, endday, 2, 0, 0);

while (startDst.GetDayOfWeek() != 1) {
  startday++;
  startDST.SetDate(2004, 4, startday);
}

while (endDst.GetDayOfWeek() != 1) {
  endday--;
  endDST.SetDate(2004, 10, endday);
}

// now startDST and endDST contain the start and end dates of daylight savings time
COleDateTime testDate(2004, 6, 12, 12, 34, 56);

if (testDate >= startDST && testDate <= endDST) {
  printf("PDT");
}
else {
  printf("PST");
}
0
 
LVL 14

Expert Comment

by:wayside
ID: 10727913
More generally, you would extract the year out of your test date and use that when building the dates for startDST and endDST.
0
 
LVL 4

Author Comment

by:astankovic
ID: 10728216
Thanks!
0
 
LVL 5

Expert Comment

by:jerry_jeremiah
ID: 10731004
Hello,

Those times you mention for DST are very specifically USA and Canada only - in fact it doesn't even really apply to all of the USA and Canada because Fort St. John, Charlie Lake, Taylor and Dawson Creek in British Columbia, Creston in the East Kootenays, and most of  Saskatchewan (except Denare Beach and Creighton) don't use daylight savings time at all.

Just to confuse things, the UK switches at one o'clock in the morning the last Sunday in March and two o'clock in the morning in October.  New Zealand did their switchover three weeks ago and Australia did their's the week after that.  Besides which, any region in the southern hemisphere that does daylight savings time does it at the opposite time of the year (Autumn here in New Zealand is in March/April)

Jerry
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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