I set Global.asax
as this:
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 that?
The ToString() method of the DateTime class is used to convert a DateTime date object to string format. The method takes a date format string that specifies the required string representation.
YYYY/MM/DD - Sortable style Gregorian date format.
What is T between date and time? The T is just a literal to separate the date from the time, and the Z means “zero hour offset” also known as “Zulu time” (UTC). If your strings always have a “Z” you can use: SimpleDateFormat format = new SimpleDateFormat( “yyyy-MM-dd'T'HH:mm:ss).
There's no such thing as "a Persian DateTime
". A DateTime
value is always a Gregorian calendar value, with no specific formatting. When you format it (usually by calling ToString
) you can determine how it's formatted - and if you use a culture which uses a non-Gregorian calendar, it will convert the original value into that calendar.
So for example, if you wanted to parse input from a Persian user and then convert that to the equivalent date that an English user would understand, you could use:
DateTime date = DateTime.Parse(text, persianCulture);
string englishText = date.ToString(englishCulture);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With