2010-03-08 50 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中

好运

相关问题