how to use nodatime for persian in c#?

穿精又带淫゛_ 提交于 2019-12-11 08:33:19

问题


nodatime 1.3 released , but i want to use nodatime in c# for Persian date time . how can i show Persian date time with Noda Time?

var london = DateTimeZoneProviders.Tzdb["Europe/London"];"

What must I do for Persian?


回答1:


You need to explicitly use the Persian calendar.

For example:

var calendar = CalendarSystem.GetPersianCalendar();
var zone = DateTimeZoneProviders.Tzdb["Europe/London"];

var now = SystemClock.Instance.Now.InZone(zone, calendar);
// Now you can get the month, etc.

Or to create a LocalDate or LocalDateTime, just pass the calendar as the final argument in the constructor call:

var localDate date = new LocalDate(1393, 4, 17, calendar);

Note that that's using the London time zone in the Persian calendar system. Calendar systems and time zones are very different things. If you want the Tehran time zone, for example, you'd use:

var zone = DateTimeZoneProviders.Tzdb["Asia/Tehran"];


来源:https://stackoverflow.com/questions/24637021/how-to-use-nodatime-for-persian-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!