Jon*_*eet 70
它实际上非常简单:
// 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
Run Code Online (Sandbox Code Playgroud)
当您调用DateTime
构造函数并传入a时Calendar
,它会为您转换它 - dt.Year
在这种情况下将是2012.如果你想走另一条路,你需要构建适当的DateTime
然后使用Calendar.GetYear(DateTime)
等.
简短但完整的计划:
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));
}
}
Run Code Online (Sandbox Code Playgroud)
打印06/27/2012 00:00:00.
Moh*_*ori 11
您可以使用此代码将波斯日期转换为格里高利.
// Persian Date
var value = "1396/11/27";
// Convert to Miladi
DateTime dt = DateTime.Parse(value, new CultureInfo("fa-IR"));
// Get Utc Date
var dt_utc = dt.ToUniversalTime();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29339 次 |
最近记录: |