How to convert date and time in CurrentCulture format to Gregorian DateTime?

I installed Global.asaxas follows:

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        PersianCulture fa = new PersianCulture();

        Thread.CurrentThread.CurrentCulture = fa;
    }

I want to convert "1392 1 23" to "2013 4 12".

How can i do this?

+5
source share
3 answers

There is no such thing as "Persian DateTime." The value is DateTimealways the Gregorian value of the calendar without special formatting. When you format it (usually by calling ToString), you can determine how it is formatted, and if you use a culture that uses a non-Gregorian calendar, it will convert the original value to this calendar.

, , , , :

DateTime date = DateTime.Parse(text, persianCulture);
string englishText = date.ToString(englishCulture);
+6

, , Datetime Datetime.

MSDN;

DateTime 00:00:00 (), 1 0001 Anno Domini ( ) 11:59:59 P.M., 31 9999 A.D. (C.E.) .

Culture DateTime, .

CultureInfo , , ​​ , , /, . DateTimeFormatInfo, NumberFormatInfo, CompareInfo TextInfo . , , , , .

+2

You can use DateTime.Parse ()

 System.Globalization.CultureInfo cultureinfo = 
    new System.Globalization.CultureInfo("en-US");
    DateTime dt = DateTime.Parse("11/04/2013", cultureinfo);
+1
source

All Articles