且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

年,月和日参数描述了波斯日历中无法表示的日期时间

更新时间:2022-02-07 21:20:36

PersianCalendar 实例获取3个 int ,然后在其构造函数中使用它们.构造函数(暗含)假定您从公历开始过去了数年,数月和数天.

DateTimes don't remember how they were created. So, e.g. d1 doesn't remember that, at some point in the past, you used a PersianCalendar instance to obtain 3 ints and then use those in its constructor. That constructor (implicitly) assumed that you were passing years, months and days from the Gregorian calendar.

然后, DateTime.Parse 不知道很久以前,您访问过 PersianCalendar 并对其进行了不当操作.

Then, further, DateTime.Parse has no knowledge that long ago you accessed a PersianCalendar and did inappropriate things with it.

如果要将波斯日历日期显示为字符串,只需将其用作:

If you want to show the Persian calendar date as a string, just use it as:

protected void lbnChangeDate_Click(object sender, EventArgs e)
{

    PersianCalendar p = new PersianCalendar();
    DateTime date = DateTime.Now;

    txtDate.Text = string.Format("{0:0000}/{1:00}/{2:00}",
                    p.GetYear(date),
                    p.GetMonth(date),
                    p.GetDayOfMonth(date));

}