如何使用 System.globalization.PersianCalendar 将波斯日期转换为公历日期?
请注意,我想转换我的波斯日期(例如今天是 1391/04/07)并获得公历日期结果,在本例中为 06/27/2012。
我正在数秒等待答案......
实际上很简单:
// I'm assuming that 1391 is the year, 4 is the month and 7 is the day
DateTime dt = new DateTime(1391, 4, 7, persianCalendar);
// Now use DateTime, which is always in the Gregorian calendar
当您致电DateTime
构造函数并传入一个Calendar
,它会为你转换它 - 所以dt.Year
在这种情况下将是 2012 年。如果你想走另一条路,你需要构建适当的DateTime
然后使用Calendar.GetYear(DateTime)
etc.
简短但完整的程序:
using System;
using System.Globalization;
class Test
{
static void Main()
{
PersianCalendar pc = new PersianCalendar();
DateTime dt = new DateTime(1391, 4, 7, pc);
Console.WriteLine(dt.ToString(CultureInfo.InvariantCulture));
}
}
打印 06/27/2012 00:00:00。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)