Click here to Skip to main content
15,867,835 members
Articles / Programming Languages / C#

Get the Time in Israel, Including DST

Rate me:
Please Sign up or sign in to vote.
4.37/5 (15 votes)
4 May 20051 min read 39.3K   11   3
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.

C#
// 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.


Written By
Software Developer (Senior)
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionyea, jews are different.. Pin
Member 139774067-Jan-20 8:23
Member 139774067-Jan-20 8:23 
QuestionWhat perfect timing Pin
Ashaman10-May-05 3:14
Ashaman10-May-05 3:14 
GeneralThank You Pin
dl4gbe5-May-05 9:17
dl4gbe5-May-05 9:17 

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

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