convert gregorian date to jalay date

Discussion in 'ASP .Net' started by h_ghanaty, Nov 7, 2003.

  1. h_ghanaty

    h_ghanaty Guest

    how i can convert gregorian date to jalaly(Iran date)
    with vb.net
    h_ghanaty, Nov 7, 2003
    #1
    1. Advertising

  2. "h_ghanaty" <> wrote in message
    news:0a5101c3a51b$3f5bb2a0$...
    > how i can convert gregorian date to jalaly(Iran date)
    > with vb.net


    I don't know VB.NET but I came up with this C# code which you can probably
    translate pretty easily. It uses the 8-of-33 leap year method which only
    works within a certain range of years because of how the Jalali leap years
    are calculated.

    const long ticksPerDay = 864000000000L;

    static int[] leapFlag =
    {0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0};

    public static void GetJalaliDate(DateTime time, out int year, out int month,
    out int day)
    {
    const int daysIn33Years = 365 * 33 + 8;
    int d = (int) (time.Ticks / ticksPerDay) - 226529;
    year = (d / daysIn33Years) * 33;
    d %= daysIn33Years;
    for (int i=0; i<33; i++)
    {
    int daysInYear = 365 + leapFlag;
    if (d < daysInYear)
    break;
    d -= daysInYear;
    year++;
    }
    if (d < 186)
    {
    month = 1 + d / 31;
    day = 1 + d % 31;
    }
    else
    {
    d -= 186;
    month = 7 + d / 30;
    day = 1 + d % 30;
    }
    }
    Bret Mulvey [MS], Nov 9, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXMgRGF2b2xp?=

    Gregorian to Julian Date conversion

    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    6,440
    Mark Rae
    Feb 3, 2005
  2. Sam
    Replies:
    1
    Views:
    5,097
    Pete Davis
    Apr 27, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,180
    Michael Borgwardt
    May 30, 2004
  4. Afanasiy

    ISO to Gregorian, strptime madness

    Afanasiy, Dec 4, 2003, in forum: Python
    Replies:
    4
    Views:
    422
    Peter Hansen
    Dec 4, 2003
  5. Lunight Sitaki

    Gregorian Calendar Error

    Lunight Sitaki, Oct 2, 2006, in forum: Java
    Replies:
    1
    Views:
    768
    mosborn
    Oct 5, 2006
Loading...

Share This Page