2010-03-08 51 views
1

我有一個sql日期格式存儲在Hijri中的表。現在我正在開發一個vb.net應用程序,我必須讓用戶更新該dateField。是否有可能將Vr中的公曆轉換爲Hijri日期?

所以有可能,如果我把一個datepicker(這是在格里高利)和用戶選擇日期和它的轉換成Hijri日期更新之前。我的意思是當用戶選擇日期並點擊保存按鈕時,日期應該以hijri格式在sql中更新。

現在,用戶在tms AdvEdit上手動輸入日期。

是否有任何代碼可用來完成此任務。提前感謝您的時間和考慮。

回答

4

下面的代碼將根據傳遞的參數轉換爲公曆/回曆:

Public Function ConvertDateCalendar(ByVal DateConv As DateTime, 
ByVal Calendar As String, ByVal DateLangCulture As String) As String 

     Dim DTFormat As DateTimeFormatInfo 
     DateLangCulture = DateLangCulture.ToLower() 
     ''' We can't have the hijri date writen in English. We will get a runtime error - LAITH - 11/13/2005 1:01:45 PM - 

     If Calendar = "Hijri" AndAlso DateLangCulture.StartsWith("en-") Then 
      DateLangCulture = "ar-sa" 
     End If 

     ''' Set the date time format to the given culture - LAITH - 11/13/2005 1:04:22 PM - 
     DTFormat = New System.Globalization.CultureInfo(DateLangCulture, False).DateTimeFormat 

     ''' Set the calendar property of the date time format to the given calendar - LAITH - 11/13/2005 1:04:52 PM - 
     Select Case Calendar 
      Case "Hijri" 
       DTFormat.Calendar = New System.Globalization.HijriCalendar() 
       Exit Select 

      Case "Gregorian" 
       DTFormat.Calendar = New System.Globalization.GregorianCalendar() 
       Exit Select 
      Case Else 

       Return "" 
     End Select 

     ''' We format the date structure to whatever we want - LAITH - 11/13/2005 1:05:39 PM - 
     DTFormat.ShortDatePattern = "dd/MM/yyyy" 
     Return (DateConv.[Date].ToString("f", DTFormat)) 
    End Function 

編碼愉快!!!!!

+1

哎ravia,謂是真棒! !!!!非常感謝 !!! – ahmed 2010-03-08 07:54:37

1

親愛的艾哈邁德,.net提供一個PersianCalendar類爲你做這個。

您只需要從PersianCalendar創建一個實例並使用它。所有的方法都是一樣熟悉並且

System.Globalization.PersianCalendar pc = new PersianCalendar(); 
pc.GetDayOfMonth(YourDate); // and so on 

注意,所有.NET庫是相同的,你可以在每個.Net平臺語言(likeVB,C#等)使用它們,他們都將編譯爲CLR,所以才創建一個實例和Ride。

我強烈建議您將格魯吉亞的日期存儲到您的數據庫,並且當您想要顯示日期,將其轉換爲波斯語或任何其他日曆時,這可讓您更簡單地將應用程序全球化。

而且需要注意的是微軟增加回歷沙姆西日曆.NET 4的的日曆,你不需要任何更多的轉換在.NET 4.0中

好運

相關問題