回历和公历日期时间构造 [英] Hijri and Gregorian DateTime constructor

查看:200
本文介绍了回历和公历日期时间构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是日历正确的行为表示反对传递给DateTime类型的构造?

what is the correct behavior for the Calendar objected passed to the constructor of DateTime type?

我有分量的年,月,日如下面的例子:

I have the components year, month and day as the below example:

day = 1
month = 5 
year = 1433 (which is the current Hijri year)

用c的结果低于$ C $是一个有效的格雷格日期创建日期时间对象时

when creating a datetime object using the below code the result is a valid Greg Date

HijriCalendar hijri = new HijriCalendar();
//Get the First Day in the Month
DateTime firstDayInMonth = new DateTime(1433, month, 1, hijri);

在使用低于code产生一个​​有效的回历日期:

while using the below code generates a valid Hijri date:

GregorianCalendar greg = new GregorianCalendar();
//Get the First Day in the Month
DateTime firstDayInMonth = new DateTime(1433, month, 1, greg);

是一个正确的结果?

is that a correct result?

推荐答案

您第一个例子是正确的。日期时间将不会在回历格式,它将是你给它的标准等同。请参见下面的$ C $下如何得到Hirji日期:

Your first example is correct. The DateTime will not be in the Hijri format, it will just be the standardised equivalent of what you gave it. See the following code for how to get the Hirji date:

HijriCalendar hijri = new HijriCalendar();
DateTime firstDayInMonth = new DateTime(1433, 10, 11, hijri);
Console.WriteLine(hijri.GetEra(firstDayInMonth)); // 1
Console.WriteLine(hijri.GetYear(firstDayInMonth)); // 1433
Console.WriteLine(hijri.GetMonth(firstDayInMonth)); // 10
Console.WriteLine(hijri.GetDayOfMonth(firstDayInMonth)); // 11

的code你的第二块刚刚设置的阳历日期1433年1月1日所以,当你检查它,你没有得到一个hirji日期,你只是让你在给它的日期15世纪。

Your second block of code was just setting the gregorian date "1/1/1433" so when you were inspecting it you weren't getting a hirji date, you were just getting the date you gave it in the 15th century.

看着 http://msdn.microsoft.com/ EN-US /库/ system.globalization.hijricalendar.aspx ,看到这些方法应该给你一个更好的主意是你应该做的日历对象上应该发生什么DateTime对象上。

Looking at http://msdn.microsoft.com/en-us/library/system.globalization.hijricalendar.aspx and seeing the methods there should give you a better idea of what you should be doing on the calendar object and what should happen on the DateTime object.

这篇关于回历和公历日期时间构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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