5
Answers

Globalization And Localization Date Problem

Photo of Nabil Nawaz

Nabil Nawaz

7y
223
1
hello guys i'm using globalization and localization in my application. i'm using 2 cultures english and arabic,
all the things are working perfectly but i'm facing issue in Date
 
in a list to records populated in JQuery Datatable when my application is in english then the date is showing correctly like 21/08/2017.
when i click on arabic and things are changed to arabic the date converted to this date  29/11/2038. i dont know why this is happening kindly help me solve this issue.
 

Answers (5)

1
Photo of Saravanan Ponnusamy
NA 1.3k 59.3k 7y
Hi,
 
Refer the following link.
 
https://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET 
1
Photo of Manikandan Murugesan
NA 20.5k 98.9k 7y
Hai Nawaz ,
Refer the following Link : https://msdn.microsoft.com/en-us/library/az4se3k1(v=VS.90).aspx
 
 
 toString() method accepts a format provider. So have like this
  1. DateTimeFormatInfo info=CultureInfo.CurrentCulture.DateTimeFormat;  
  2. DateTime.Now.Day.ToString(info); 
 
1
Photo of Nabil Nawaz
NA 186 3.8k 7y
thankyou guys for your reply !
 
i just changed "ar-SA" to "ar-BH" and problem is solved. date only gets changed with "ar-SA" by all others like "ar-AE" and other it's not get changed
1
Photo of Gokhul Varman
NA 10.7k 9.4k 7y
Please refer the link for detailed explanation:https://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx
1
Photo of Manas Mohapatra
NA 29.3k 3.3m 7y
Try wih below code:
  1. public static string ConvertDateCalendar(DateTime DateConv, string Calendar, string DateLangCulture)  
  2. {  
  3.     DateTimeFormatInfo DTFormat;  
  4.     DateLangCulture = DateLangCulture.ToLower();  
  5.     /// We can't have the hijri date writen in English. We will get a runtime error  
  6.   
  7.     if (Calendar == "Hijri" && DateLangCulture.StartsWith("en-"))  
  8.     {  
  9.         DateLangCulture = "ar-sa";  
  10.     }  
  11.   
  12.     /// Set the date time format to the given culture  
  13.     DTFormat = new System.Globalization.CultureInfo(DateLangCulture, false).DateTimeFormat;  
  14.   
  15.     /// Set the calendar property of the date time format to the given calendar  
  16.     switch (Calendar)  
  17.     {  
  18.         case "Hijri":  
  19.             DTFormat.Calendar = new System.Globalization.HijriCalendar();  
  20.             break;  
  21.   
  22.         case "Gregorian":  
  23.             DTFormat.Calendar = new System.Globalization.GregorianCalendar();  
  24.             break;  
  25.   
  26.         default:  
  27.             return "";  
  28.     }  
  29.   
  30.     /// We format the date structure to whatever we want  
  31.     DTFormat.ShortDatePattern = "dd/MM/yyyy";  
  32.     return (DateConv.Date.ToString("f", DTFormat));  
  33. }  
  34.   
  35. DateTime dtq = new DateTime(2017, 08, 21);  
  36. string date = ConvertDateCalendar(dtq, "Hijri""en-US");  
Follow below link, that may help you:
 
http://www.c-sharpcorner.com/blogs/arabic-calendar-date-to-english-calendar-date-in-windows-form-c-sharp1