h_ghanaty said:
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;
}
}