希望在persianCalnder中获得DayOfWeek,但它始终与Georgian Calender相同,
DateTime today = DateTime.Today;
PersianCalendar pc = new PersianCalendar();
var geDayOfWeek= today.DayOfWeek;
var pcDayOfWeek=pc.GetDayOfWeek(today);
为什么geDayOfWeek和pcDayOfWeek的值始终相同?波斯周在星期六而不是星期一开始,所以例如星期日应该是2而不是0。
在波斯日历中获取日期编号的任何解决方案?
我需要这个来计算波斯日历中的开始日期和结束日期,而不是格鲁吉亚日历。
答案 0 :(得分:0)
你可以为DateTime编写一个扩展方法来获得Persion Day of Week
public static class DateTimeHelper
{
public static PersianDayOfWeek PersionDayOfWeek(this DateTime date)
{
switch (date.DayOfWeek)
{
case DayOfWeek.Saturday:
return PersianDayOfWeek.Shanbe;
case DayOfWeek.Sunday:
return PersianDayOfWeek.Yekshanbe;
case DayOfWeek.Monday:
return PersianDayOfWeek.Doshanbe;
case DayOfWeek.Tuesday:
return PersianDayOfWeek.Seshanbe;
case DayOfWeek.Wednesday:
return PersianDayOfWeek.Charshanbe;
case DayOfWeek.Thursday:
return PersianDayOfWeek.Panjshanbe;
case DayOfWeek.Friday:
return PersianDayOfWeek.Jome;
default:
throw new Exception();
}
}
public enum PersianDayOfWeek
{
Shanbe=1,
Yekshanbe=2,
Doshanbe=3,
Seshanbe=4,
Charshanbe=5,
Panjshanbe=6,
Jome=7
}
}
你可以像这样使用它:
PersianDayOfWeek DoW = DateTime.Now.PersionDayOfWeek();