1

I am building a multilingual MVC 4 Web Application (English, Spanish, Arabic ...), for the Internationalization part i followed This Tutorial, everything is fine so far, except on little detail, when choosing Arabic, all Date Data show up in Hijri (02/04/1436) when i want the Gregorian calendar, and since i need the cultureInfo to be dynamic, i can't set a default/Global Culture for the web app. is there a way to solve this issue by specifying the date to take a specific culture ?

Model

    [Display(Name = "EntryDate", ResourceType = typeof(Resources.i18n))]
    [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    public DateTime EntryDate { get; set; }

View

<td>@Html.DisplayFor(modelItem => item.EntryDate)</td>
Mugiwara
  • 866
  • 1
  • 11
  • 33

2 Answers2

1

You can use the below code to get the culture based on the selected option and transform the date accordingly.

CultureInfo us = new CultureInfo("en-US");
string shortUsDateFormatString = us.DateTimeFormat.ShortDatePattern;
string shortUsTimeFormatString = us.DateTimeFormat.ShortTimePattern;

This will help you get control over the date based on the selected option and have them displayed in your particular format.

Kaustav Banerjee
  • 275
  • 1
  • 10
1

Alight i found it, thanks you all.

CultureInfo arSA = new CultureInfo("ar-SA");
arSA.DateTimeFormat.Calendar = new HijriCalendar();
var dateValue = DateTime.ParseExact("29/08/1434", "dd/MM/yyyy", arSA);

it returns 7/7/2013

Mugiwara
  • 866
  • 1
  • 11
  • 33