hi friends. I have a datagrid which populated by some data from sqlserver.I have datetime filed that represent Georgian date,but i want to convert this to Persian by using PersianCalendar. I wan some kind of conversion, that gets Georgian date from database but when it comes to show on datagrid or some where else, it shows persian date.
A:
For formatting you need to use the appropriate CultureInfo class, not the calendar - the names of persian cultures are fa
or fa-IR
, as can be seen here.
CultureInfo farsi = new CultureInfo("fa-IR");
farsi.DateTimeFormat.Calendar = new PersianCalendar();
DateTime date1 = new DateTime(1867, 1, 1);
Console.WriteLine(date1.ToString(farsi));
Update:
You can use the ItemDataBound
event of the grid in order to format the date exactly as you want.
Oded
2010-07-27 06:19:57
how can i use this in datagrid view or some other places in asp.net ?
persian Dev
2010-07-27 06:22:08
@persian Dev - You need to set the thread culture of the app (UI thread if a winforms app), to the Persian culture. http://msdn.microsoft.com/en-us/library/bz9tc508.aspx
Oded
2010-07-27 06:42:45
thank you dear Oded
persian Dev
2010-07-27 07:12:40
i used <globalization culture="fa-IR" /> but the date format does not change to persian format.
persian Dev
2010-07-27 08:06:41
@persian Dev - Did you also set the `uiCulture="fa-IR"`?
Oded
2010-07-27 08:08:09
use i have used it, but just changed the direction of error pages as i see.
persian Dev
2010-07-27 08:19:46
@persian Dev - Are you using winforms or webforms or wpf?
Oded
2010-07-27 08:25:25
i am using webforms, ASP.NET 3.5
persian Dev
2010-07-27 08:33:40