转换日历 [英] converting calendars
本文介绍了转换日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这些代码将公历转换为儒略历,没有问题.
I use these codes to convert Gregorian calendar to Julian calendar and there's no problem.
private void button1_Click(object sender, EventArgs e)
{
JulianCalendar juli = new JulianCalendar();
DateTime dt = Convert.ToDateTime(textBox1.Text);
int day = juli.GetDayOfMonth(dt);
int month = juli.GetMonth(dt);
int year = juli.GetYear(dt);
string s = string.Format("{0}/{1}/{2}", month, day, year);
textBox2.Text = s;
}
它给了我 Julian 日期时间,但是当我想将它再次转换为具有该日期时间的公历时,它不起作用.我使用以下代码将儒略历转换为公历.有什么问题?
It gives me the Julian date time but when i want to convert it again to Gregorian calendar with exactly that date time it won't work. i use these following codes for converting Julian calendar to Gregorian calendar. what's the problem?
private void button2_Click(object sender, EventArgs e)
{
string juli = textBox3.Text;
string[] parts = juli.Split('/', '-');
JulianCalendar jul = new JulianCalendar();
DateTime dta = jul.ToDateTime(Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1]), Convert.ToInt32(parts[2]), 0, 0, 0, 0);
string sta = dta.ToShortDateString();
textBox4.Text = sta;
}
推荐答案
问题出在参数的顺序上.应该是(在 button2_Click 事件中)
the problem is in the order of the paremeters. It should be (in button2_Click event)
DateTime dta = juli2.ToDateTime(Convert.ToInt32(parts[2]), Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1]), 0, 0, 0, 0);
因为 ToDateTime 方法的签名如下:
because the signature of ToDateTime method is the following:
public virtual System.DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
这篇关于转换日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文