转换日期从波斯湾到公历 [英] Convert Date from Persian to Gregorian

查看:153
本文介绍了转换日期从波斯湾到公历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换波斯日期使用System.globalization.PersianCalendar公历日期? 请注意,我想将我的波斯日期(例如:今天是1391年4月7日),并获得阳历日期的结果,这将是在这种情况下,06月27日。 我指望秒的答案...

How can I convert Persian date to Gregorian date using System.globalization.PersianCalendar? Please note that I want to convert my Persian Date (e.g. today is 1391/04/07) and get the Gregorian Date result which will be 06/27/2012 in this case. I'm counting seconds for an answer ...

推荐答案

你的意思是阳历?我不知道一个格鲁吉亚日历。

Do you mean Gregorian? I'm not aware of a Georgian calendar.

如果是这样,这是pretty的其实很简单:

If so, it's pretty simple actually:

// 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 构造,并通过了日历,将其转换为你 - 这样 dt.Year 将在2012年在这种情况下。如果你想要去的其他方式,你需要构建相应的的DateTime 然后用 Calendar.GetYear(日期时间)等等。

When you call the DateTime constructor and pass in a Calendar, it converts it for you - so dt.Year would be 2012 in this case. If you want to go the other way, you need to construct the appropriate DateTime then use Calendar.GetYear(DateTime) etc.

短,但完整的程序:

using System;
using System.Globalization;

class Test
{
    static void Main()
    {
        DateTime dt = new DateTime(1391, 4, 7);
        Console.WriteLine(dt.ToString(CultureInfo.InvariantCulture));
    }
}

这版画06月27日00:00:00。

That prints 06/27/2012 00:00:00.

这篇关于转换日期从波斯湾到公历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆