Click here to Skip to main content
11,635,098 members (76,801 online)
Click here to Skip to main content

Get the time in Israel, including DST

, 4 May 2005 33.5K 11
Rate this:
Please Sign up or sign in to vote.
The formula for DST in Israel is unique and based on the Jewish calendar. This function knows how to calculate this formula.

Introduction

The entailed function calculates the correct time in Israel, based on the derivation from GMT (Greenwich Mean Time) and DST (Daylight Summer Time).

Background

The basic calendar in Israel is the Jewish one, not the Gregorian one. The Jewish holidays start at sunset. So adding one hour to the clock postpones the holiday to start later, which is difficult for the kids. Another deviation of the Jewish calendar is that the Israeli weekend is Friday and Saturday instead of Saturday and Sunday.

Over the last 60 years, a ministerial clerk used to determine the beginning and end of DST each single year. It caused many problems - to airline companies, conference organizers and to us - the developers.

This year, a new law was approved, which makes end to this story. From 2005, the DST will start on last Friday before April 2nd, and finish on last Sunday before Yom HaKipurim - the holiest Jewish day (which is also a fast day). Both times are at 2:00 AM.

Using the code

The function takes this formula and calculates the correct time in Israel.

// supply a default
public static DateTime GetIsraelTime() {
    return (GetIsraelTime(DateTime.UtcNow));
}

// input: UTC DateTime object
public static DateTime GetIsraelTime(DateTime d) {
    d = d.AddHours(2);           // Israel is at GMT+2

    // April 2nd, 2:00 AM
    DateTime DSTStart = new DateTime(d.Year, 4, 2, 2, 0 ,0);  
    while (DSTStart.DayOfWeek != DayOfWeek.Friday)
        DSTStart = DSTStart.AddDays(-1);

    CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");
    System.Globalization.HebrewCalendar cal = 
          new System.Globalization.HebrewCalendar();
    jewishCulture.DateTimeFormat.Calendar = cal;
    // Yom HaKipurim, at the start of the next Jewish year, 2:00 AM
    DateTime DSTFinish =
         new DateTime(cal.GetYear(DSTStart)+1, 1, 10, 2, 0 ,0, cal);
    while (DSTFinish.DayOfWeek != DayOfWeek.Sunday)
        DSTFinish= DSTFinish.AddDays(-1);

    if (d>DSTStart && d<DSTFinish)
        d = d.AddHours(1);

    return (d);
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

YoniP
Software Developer (Senior)
Israel Israel
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionWhat perfect timing Pin
Ashaman10-May-05 3:14
memberAshaman10-May-05 3:14 
GeneralThank You Pin
dl4gbe5-May-05 9:17
memberdl4gbe5-May-05 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150728.1 | Last Updated 5 May 2005
Article Copyright 2005 by YoniP
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid