logo VB.Net - Converting Calendar Dates
Guide Contents
DigitalDan Home Page

Calendars
This section provides a set of functions for converting dates between calendars. E.g. Convert a date in the normal western (Gregorian) calendar to the equivilent date using the Chinese LuniSolar Calendar.
 
When converting between calendars, it is very important to understand how each of your chosen calenders work. Converting to/from unfamiliar calendars is likely to produce unexpected results for a variety of reasons including the following...
 
The VB.Net Date command adjusts itself, according to system settings etc. This can cause confusion when using multiple calendars. When using certain calendars we also need to identify any leap months. For this reason, these examples all use a custom date structure (I have called this YMD) which includes Year, Month, Day and LeapMonth. When LeapMonth is set,it will identify the month number for the leap month in the specified year. LeapMonth = 0 indicates that either the calendar does not use leap months or that there is no leap month in the requested year.
 
Date structure used with Calendar functions
Private Structure YMD
Dim Y As Integer
' year number
Dim m As Integer
' month number in year
Dim d As Integer
' day nummer in month
Dim LeapMonth As Integer
' LeapMonth is not used by some calendars - it can be set to 0 when not required
End Structure

 
Calendar Conversion Functions
This function is required by many of the date converion routines
 
Private Shared Function DDif(y As Integer, md1 As Integer, md2 As Integer) As Integer
Dim dat1, dat2 As Date
dat1 = New Date(y, CInt(md1 \ 100), md1 Mod 100, 12, 0, 0, 0)
dat2 = New Date(y, CInt(md2 \ 100), md2 Mod 100, 12, 0, 0, 0)
Return 1 + CInt(DateDiff(DateInterval.Day, dat1, dat2))
End Function

 
And Finally, here is an assortment of date conversion functions
 
Private Shared Function Chinese_Date_To_Gregorian_Date(ChinDate As YMD) As YMD
Dim ret As New YMD
Dim dat As Date
Try
Dim chinese As New Globalization.ChineseLunisolarCalendar
Dim gregorian As New Globalization.GregorianCalendar
Dim chineseDate As Date = chinese.ToDateTime(ChinDate.Y, ChinDate.m, ChinDate.d, 12, 0, 0, 0)
dat = New Date(gregorian.GetYear(chineseDate), gregorian.GetMonth(chineseDate), gregorian.GetDayOfMonth(chineseDate), 12, 0, 0, 0)
ret.Y = dat.Year : ret.m = dat.Month : ret.d = dat.Day
Catch ex As Exception
ret.Y = 0 : ret.m = 0 : ret.d = 0 : ret.LeapMonth = 0
End Try
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Chinese_Date(ymd1 As YMD) As YMD
Dim ret As YMD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim gChin As New Globalization.ChineseLunisolarCalendar
Dim CurCulture As String = Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag
Dim newCulture As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("zh-CN")
Threading.Thread.CurrentThread.CurrentUICulture = newCulture
Threading.Thread.CurrentThread.CurrentCulture = newCulture
' Make current UI culture consistent with current culture.
ret.Y = gChin.GetYear(dat)
ret.m = gChin.GetMonth(dat)
ret.d = gChin.GetDayOfMonth(dat)
ret.LeapMonth = gChin.GetLeapMonth(dat.Year)
Threading.Thread.CurrentThread.CurrentUICulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Return ret
End Function
'
Private Shared Function Year_and_Day_Number_To_Gregorian_Date(ym1 As YD) As YMD
Dim dat As New Date(ym1.Y, 1, 1, 12, 0, 0, 0)
dat = dat.AddDays(ym1.d - 1)
Dim ret As YMD
If dat.Year <> ym1.Y Then
ret.Y = 0 : ret.m = 0 : ret.d = 0 : ret.LeapMonth = 0
Return ret
End If
ret.Y = dat.Year : ret.m = dat.Month : ret.d = dat.Day : ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Year_and_Day_Number(ymd1 As YMD) As YD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim ret As YD
If ((dat.Year <> ymd1.Y) Or (dat.Month <> ymd1.m) Or (dat.Day <> ymd1.d)) Then
ret.Y = 0 : ret.d = 0
Return ret
End If
ret.Y = dat.Year : ret.d = dat.DayOfYear
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Epoch_Date(gregDate As YMD, epochDate As YMD) As Integer
Dim gDate As New Date(gregDate.Y, gregDate.m, gregDate.d, 12, 0, 0, 1, 0)
Dim eDate As New Date(epochDate.Y, epochDate.m, epochDate.d, 12, 0, 0, 0, 0)
Dim t As Long = DateDiff(DateInterval.Day, eDate, gDate)
Return CInt(t)
' Epoch calendars are all based on counting days from an epochDate
' Leap month is not used and can be set to 0
' NT Day (Epoch 1601) = 01/01/1601
' Unix Day (Epoch 1970) = 01/01/1970
' Day Count (Epoch 1980) = 01/01/1980
' Millenium (Epoch 2000) = 01/01/2000
' Post Covid (Epoch 2020)= 01/01/2020
End Function
'
Private Shared Function Epoch_Date_To_Gregorian_Date(epoch As Integer, epochdate As YMD) As YMD
Dim ret As YMD
Dim eDate As New Date(epochdate.Y, epochdate.m, epochdate.d, 12, 0, 0, 0)
eDate = eDate.AddDays(epoch)
ret.Y = eDate.Year : ret.m = eDate.Month : ret.d = eDate.Day : ret.LeapMonth = 0
Return ret
' Epoch calendars are all based on counting days from an epochDate
' Leap month is not used and can be set to 0
' NT Day (Epoch 1601) = 01/01/1601
' Unix Day (Epoch 1970) = 01/01/1970
' Day Count (Epoch 1980) = 01/01/1980
' Millenium (Epoch 2000) = 01/01/2000
' Post Covid (Epoch 2020)= 01/01/2020
End Function
'
Private Shared Function Gregorian_Date_To_Hebrew_Date(ymd1 As YMD) As YMD
Dim ret As YMD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim gHeb As New Globalization.HebrewCalendar
Dim CurCulture As String = Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag
Dim newCulture As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("he-IL")
Threading.Thread.CurrentThread.CurrentUICulture = newCulture
Threading.Thread.CurrentThread.CurrentCulture = newCulture
' Make current UI culture consistent with current culture.
ret.Y = gHeb.GetYear(dat)
ret.m = gHeb.GetMonth(dat)
ret.d = gHeb.GetDayOfMonth(dat)
ret.LeapMonth = gHeb.GetLeapMonth(ret.Y)
Threading.Thread.CurrentThread.CurrentUICulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
End Function
'
Private Shared Function Hebrew_Date_To_Gregorian_Date(HebDate As YMD) As YMD
Dim ret As New YMD
Dim dat As Date
Try
Dim hebrew As New Globalization.HebrewCalendar
Dim gregorian As New Globalization.GregorianCalendar
Dim hebrewDate As Date = hebrew.ToDateTime(HebDate.Y, HebDate.m, HebDate.d, 12, 0, 0, 0)
dat = New Date(gregorian.GetYear(hebrewDate), gregorian.GetMonth(hebrewDate), gregorian.GetDayOfMonth(hebrewDate), 12, 0, 0, 0)
ret.Y = dat.Year : ret.m = dat.Month : ret.d = dat.Day : ret.LeapMonth = 0
Catch ex As Exception
ret.Y = 0 : ret.m = 0 : ret.d = 0 : ret.LeapMonth = 0
End Try
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Hijri_Date(ymd1 As YMD, Optional adjustment As Integer = 0) As YMD
Dim ret As YMD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim gHij As New Globalization.HijriCalendar
If ((adjustment < -2) Or (adjustment > 2)) Then adjustment = 0
gHij.HijriAdjustment = adjustment
Dim CurCulture As String = Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag
Dim newCulture As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("ar-JO")
Threading.Thread.CurrentThread.CurrentUICulture = newCulture
Threading.Thread.CurrentThread.CurrentCulture = newCulture
ret.Y = gHij.GetYear(dat)
ret.m = gHij.GetMonth(dat)
ret.d = gHij.GetDayOfMonth(dat)
ret.LeapMonth = gHij.GetLeapMonth(dat.Year)
Threading.Thread.CurrentThread.CurrentUICulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Return ret
End Function
'
Private Shared Function Hijri_Date_To_Gregorian_Date(ymd1 As YMD, Optional adjustment As Integer = 0) As YMD
Dim gIn As New Globalization.HijriCalendar
If ((adjustment < -2) Or (adjustment > 2)) Then adjustment = 0
gIn.HijriAdjustment = adjustment
Dim gout As New Globalization.GregorianCalendar
Dim date1 As New DateTime(ymd1.Y, ymd1.m, ymd1.d, gIn)
Dim ret As YMD
ret.Y = gout.GetYear(date1) : ret.m = gout.GetMonth(date1) : ret.d = gout.GetDayOfMonth(date1) : ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Indian_Civil_dsate_To_Gregorian_Date(ymd1 As YMD) As YMD
Dim leaptest As Integer = ymd1.Y + 78
Dim isleap As Boolean = False
If leaptest Mod 4 = 0 Then isleap = True
If leaptest Mod 100 = 0 Then isleap = False
If leaptest Mod 400 = 0 Then isleap = True
Dim dat As New Date(2000, 1, 1, 12, 0, 0, 0, 0)
' Get date on first of the Indian Month
Select Case ymd1.m
Case 1
If isleap Then
dat = New Date(ymd1.Y + 78, 3, 21, 12, 0, 0, 0, 0)
Else
dat = New Date(ymd1.Y + 78, 3, 22, 12, 0, 0, 0, 0)
End If
Case 2 : dat = New Date(ymd1.Y + 78, 4, 21, 12, 0, 0, 0, 0)
Case 3 : dat = New Date(ymd1.Y + 78, 5, 22, 12, 0, 0, 0, 0)
Case 4 : dat = New Date(ymd1.Y + 78, 6, 22, 12, 0, 0, 0, 0)
Case 5 : dat = New Date(ymd1.Y + 78, 7, 23, 12, 0, 0, 0, 0)
Case 6 : dat = New Date(ymd1.Y + 78, 8, 23, 12, 0, 0, 0, 0)
Case 7 : dat = New Date(ymd1.Y + 78, 9, 23, 12, 0, 0, 0, 0)
Case 8 : dat = New Date(ymd1.Y + 78, 10, 23, 12, 0, 0, 0, 0)
Case 9 : dat = New Date(ymd1.Y + 78, 11, 22, 12, 0, 0, 0, 0)
Case 10 : dat = New Date(ymd1.Y + 78, 12, 22, 12, 0, 0, 0, 0)
Case 11 : dat = New Date(ymd1.Y + 77, 1, 21, 12, 0, 0, 0, 0)
Case 12 : dat = New Date(ymd1.Y + 78, 2, 20, 12, 0, 0, 0, 0)
End Select
dat = DateAdd(DateInterval.Day, ymd1.d - 1, dat)
If ymd1.m = 10 And ymd1.d >= 10 Then dat = DateAdd(DateInterval.Year, 1, dat)
Dim ret As YMD
ret.Y = dat.Year
ret.m = dat.Month
ret.d = dat.Day
ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Indian_Civil_Date(ymd1 As YMD) As YMD
Dim Leap As Boolean = False
If ymd1.Y Mod 4 = 0 Then Leap = True
If ymd1.Y Mod 100 = 0 Then Leap = False
If ymd1.Y Mod 400 = 0 Then Leap = True
Dim gMD As Integer = ymd1.m * 100 + ymd1.d
Dim iY As Integer = 0
Dim iM As Integer = 0
Dim iD As Integer = 0
Dim iMD(12) As Integer
If gMD >= 101 And gMD < 121 Then iY = ymd1.Y - 77 : iM = 10 : iD = DDif(ymd1.Y, 101, gMD) + 10
If gMD >= 121 And gMD < 220 Then iY = ymd1.Y - 77 : iM = 11 : iD = DDif(ymd1.Y, 121, gMD)
If Leap Then
If gMD >= 220 And gMD < 321 Then iY = ymd1.Y - 77 : iM = 12 : iD = DDif(ymd1.Y, 220, gMD)
If gMD >= 321 And gMD < 421 Then iY = ymd1.Y - 78 : iM = 1 : iD = DDif(ymd1.Y, 321, gMD)
Else
If gMD >= 220 And gMD < 322 Then iY = ymd1.Y - 77 : iM = 12 : iD = DDif(ymd1.Y, 220, gMD)
If gMD >= 322 And gMD < 421 Then iY = ymd1.Y - 78 : iM = 1 : iD = DDif(ymd1.Y, 322, gMD)
End If
If gMD >= 421 And gMD < 522 Then iY = ymd1.Y - 78 : iM = 2 : iD = DDif(ymd1.Y, 421, gMD)
If gMD >= 522 And gMD < 623 Then iY = ymd1.Y - 78 : iM = 3 : iD = DDif(ymd1.Y, 522, gMD)
If gMD >= 623 And gMD < 723 Then iY = ymd1.Y - 78 : iM = 4 : iD = DDif(ymd1.Y, 623, gMD)
If gMD >= 723 And gMD < 823 Then iY = ymd1.Y - 78 : iM = 5 : iD = DDif(ymd1.Y, 723, gMD)
If gMD >= 823 And gMD < 923 Then iY = ymd1.Y - 78 : iM = 6 : iD = DDif(ymd1.Y, 823, gMD)
If gMD >= 923 And gMD < 1023 Then iY = ymd1.Y - 78 : iM = 7 : iD = DDif(ymd1.Y, 923, gMD)
If gMD >= 1023 And gMD < 1122 Then iY = ymd1.Y - 78 : iM = 8 : iD = DDif(ymd1.Y, 1023, gMD)
If gMD >= 1122 And gMD < 1222 Then iY = ymd1.Y - 78 : iM = 9 : iD = DDif(ymd1.Y, 1122, gMD)
If gMD >= 1222 And gMD < 9999 Then iY = ymd1.Y - 78 : iM = 10 : iD = DDif(ymd1.Y, 1222, gMD)
Dim ret As YMD
ret.Y = iY : ret.m = iM : ret.d = iD : ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Iso_Date(dat As Date) As ISO
' note some software uses non standard Week/day numbering systems
' this function is based on the offcial ISO standard
Dim ret As ISO
Dim FirstDay As Date = ISOFirstMonday(dat)
Dim days As Integer
If dat >= FirstDay Then
ret.y = dat.Year
ret.d = (dat.DayOfWeek + 6) Mod 7 + 1
days = CInt(DateDiff(DateInterval.Day, FirstDay, dat))
ret.w = (days \ 7) + 1
Return ret
End If
' if we get here, the ISO week is based on previous ISO year (first few days of Jan)
Dim dat2 As Date = dat.AddYears(-1)
FirstDay = ISOFirstMonday(dat2)
ret.y = dat.Year - 1
ret.d = (dat.DayOfWeek + 6) Mod 7 + 1
days = CInt(DateDiff(DateInterval.Day, FirstDay, dat))
ret.w = (days \ 7) + 1
Return ret
End Function
Private Shared Function ISOFirstMonday(dat1 As Date) As Date
Dim MondayWeekOne As New Date(dat1.Year, 1, 4, 12, 0, 0, 0)
While MondayWeekOne.DayOfWeek <> DayOfWeek.Monday
MondayWeekOne = MondayWeekOne.AddDays(-1)
End While
Return MondayWeekOne
End Function
'
Private Shared Function Iso_Date_To_Gregorian_Date(iso1 As ISO) As YMD
Dim daycount As Integer = ((iso1.w - 1) * 7) + (iso1.d - 1)
' initially assume Greg year matches Iso Year (we will fix year-bounces later)
Dim year As Integer = iso1.y
'get date of first monday (30 June chosen because it is well away from any Iso/Greg year mismatches)
Dim FMdat As Date = ISOFirstMonday(New Date(year, 6, 30, 12, 0, 0, 0))
' get "posible" date - if we have correct GregYear
Dim testDat As Date = FMdat.AddDays(163)
While testDat.Year < iso1.y
year -= 1
FMdat = ISOFirstMonday(New Date(year, 6, 30, 12, 0, 0, 0))
testDat = FMdat.AddDays(163)
End While
While testDat.Year > iso1.y
year += 1
FMdat = ISOFirstMonday(New Date(year, 6, 30, 12, 0, 0, 0))
testDat = FMdat.AddDays(163)
End While
' return the result
Dim gDat As Date = FMdat.AddDays(daycount)
Dim ret As YMD
ret.Y = gDat.Year : ret.m = gDat.Month : ret.d = gDat.Day : ret.LeapMonth = 0
Return ret
End Function
Private Shared Function ISOFirstMonday(dat1 As Date) As Date
Dim MondayWeekOne As New Date(dat1.Year, 1, 4, 12, 0, 0, 0)
While MondayWeekOne.DayOfWeek <> DayOfWeek.Monday
MondayWeekOne = MondayWeekOne.AddDays(-1)
End While
Return MondayWeekOne
End Function
'
Private Shared Function Gregorian_Date_To_Julian_Date(ymd1 As YMD) As YMD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim TryDat As Date
Dim tryYMD As YMD
Dim newGreg As YMD
tryYMD.LeapMonth = 0
' try -13 days first - that will work for all of 1901 to 2099
TryDat = dat.AddDays(-13)
tryYMD.Y = TryDat.Year : tryYMD.m = TryDat.Month : tryYMD.d = TryDat.Day : tryYMD.LeapMonth = 0
newGreg = Julian_Date_To_Gregorian_Date(tryYMD)
If ((newGreg.d = ymd1.d) AndAlso (newGreg.m = ymd1.m) AndAlso (newGreg.Y = ymd1.Y)) Then
Return tryYMD
End If
' ok lets try values for +/- a few centuaries
For i As Integer = -17 To -10
TryDat = dat.AddDays(i)
tryYMD.Y = TryDat.Year : tryYMD.m = TryDat.Month : tryYMD.d = TryDat.Day : tryYMD.LeapMonth = 0
newGreg = Julian_Date_To_Gregorian_Date(tryYMD)
If ((newGreg.d = ymd1.d) AndAlso (newGreg.m = ymd1.m) AndAlso (newGreg.Y = ymd1.Y)) Then
Exit For
End If
Next
Return tryYMD
End Function
'
Private Shared Function Julian_Date_To_Gregorian_Date(ymd1 As YMD) As YMD
Dim gIn As New Globalization.JulianCalendar
Dim gout As New Globalization.GregorianCalendar
Dim date1 As New DateTime(ymd1.Y, ymd1.m, ymd1.d, gIn)
Dim ret As YMD
ret.Y = gout.GetYear(date1) : ret.m = gout.GetMonth(date1) : ret.d = gout.GetDayOfMonth(date1) : ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Modified_Julian_Day(ymd1 As YMD) As Integer
Dim dat As New Date(1858, 11, 17, 12, 0, 0, 0)
Dim ret As Integer
ret = CInt(DateDiff(DateInterval.Day, dat, New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 1, 0)))
Return ret
End Function
'
Private Shared Function Modified_Julian_Day_To_Gregorian_Date(mjd As Integer) As YMD
Dim ret As YMD
Dim dat As New Date(1858, 11, 17, 12, 0, 0, 0)
dat = dat.AddDays(mjd)
ret.Y = dat.Year : ret.m = dat.Month : ret.d = dat.Day : ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Korean_Date(ymd1 As YMD) As YMD
Dim ret As YMD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim gKor As New Globalization.KoreanCalendar
Dim CurCulture As String = Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag
Dim newCulture As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("ko-KR")
Threading.Thread.CurrentThread.CurrentUICulture = newCulture
Threading.Thread.CurrentThread.CurrentCulture = newCulture
ret.Y = gKor.GetYear(dat)
ret.m = gKor.GetMonth(dat)
ret.d = gKor.GetDayOfMonth(dat)
ret.LeapMonth = gKor.GetLeapMonth(ret.Y)
Threading.Thread.CurrentThread.CurrentUICulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Return ret
End Function
'
Private Shared Function Korean_Date_To_Gregorian_Date(ymd1 As YMD) As YMD
Dim gIn As New Globalization.KoreanCalendar
Dim gout As New Globalization.GregorianCalendar
Dim date1 As New DateTime(ymd1.Y, ymd1.m, ymd1.d, gIn)
Dim ret As YMD
ret.Y = gout.GetYear(date1) : ret.m = gout.GetMonth(date1) : ret.d = gout.GetDayOfMonth(date1) : ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_Korean_Lunisolar_Date(ymd1 As YMD) As YMD
Dim ret As YMD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim gKor As New Globalization.KoreanLunisolarCalendar
Dim CurCulture As String = Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag
Dim newCulture As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("ko-KR")
Threading.Thread.CurrentThread.CurrentUICulture = newCulture
Threading.Thread.CurrentThread.CurrentCulture = newCulture
ret.Y = gKor.GetYear(dat)
ret.m = gKor.GetMonth(dat)
ret.d = gKor.GetDayOfMonth(dat)
ret.LeapMonth = gKor.GetLeapMonth(ret.Y)
Threading.Thread.CurrentThread.CurrentUICulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Return ret
End Function
'
Private Shared Function Korean_Lunisolar_Date_To_Gregorian_Date(ymd1 As YMD) As YMD
Dim gIn As New Globalization.KoreanLunisolarCalendar
Dim gout As New Globalization.GregorianCalendar
Dim date1 As New DateTime(ymd1.Y, ymd1.m, ymd1.d, gIn)
Dim ret As YMD
ret.Y = gout.GetYear(date1) : ret.m = gout.GetMonth(date1) : ret.d = gout.GetDayOfMonth(date1) : ret.LeapMonth = 0
Return ret
End Function
'
Private Shared Function Gregorian_Date_To_UmAlQura_Date(ymd1 As YMD) As YMD
Dim ret As YMD
Dim dat As New Date(ymd1.Y, ymd1.m, ymd1.d, 12, 0, 0, 0)
Dim gUm As New Globalization.UmAlQuraCalendar
Dim CurCulture As String = Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag
Dim newCulture As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("ar-SA")
Threading.Thread.CurrentThread.CurrentUICulture = newCulture
Threading.Thread.CurrentThread.CurrentCulture = newCulture
ret.Y = gUm.GetYear(dat)
ret.m = gUm.GetMonth(dat)
ret.d = gUm.GetDayOfMonth(dat)
ret.LeapMonth = gUm.GetLeapMonth(ret.Y)
Threading.Thread.CurrentThread.CurrentUICulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(CurCulture)
Return ret
End Function
'
Private Shared Function UmAlQura_Date_To_Gregorian_Date(ymd1 As YMD) As YMD
Dim gIn As New Globalization.UmAlQuraCalendar
Dim gout As New Globalization.GregorianCalendar
Dim date1 As New DateTime(ymd1.Y, ymd1.m, ymd1.d, gIn)
Dim ret As YMD
ret.Y = gout.GetYear(date1) : ret.m = gout.GetMonth(date1) : ret.d = gout.GetDayOfMonth(date1) : ret.LeapMonth = 0
Return ret
End Function

DigitalDan.co.uk ... Hits = 309