日期:2014-05-20  浏览次数:20808 次

一个月的天数通过天数怎么算出星期几
就是我选12月份,点确定

下面是这样    
第一行   :1       2       3       4       5       6       7           8           9。。。。
第二行:日     一     二     三       四     五     六       日         一


就是第一行显示一个月的多少天,第二行要把对应的星期几,显示出来,
想问一下,这个怎么弄啊?



------解决方案--------------------
DateTime dt = new DateTime();
dt.DayOfWeek // 用这个
------解决方案--------------------
必须输入年份。
Console.WriteLine( "请输入年份,并按回车键确认。 ");
int year;
while(!Int32.TryParse(Console.ReadLine(), out year) || year <=0)
{
Console.WriteLine( "请输入年份,并按回车键确认。 ");
}
Console.WriteLine( "请输入月份,并按回车键确认。 ");
int month;
while(!Int32.TryParse(Console.ReadLine(), out month) || month <=0 || month > 12)
{
Console.WriteLine( "请输入月份,并按回车键确认。 ");
}
Console.WriteLine( "{0}年{1}月: ", year, month);
System.Text.StringBuilder sbDays = new System.Text.StringBuilder();
System.Text.StringBuilder sbWeeks = new System.Text.StringBuilder();
int days = DateTime.DaysInMonth(year, month);
DateTime dt;
for(int i = 1; i <= days; ++i)
{
dt = new DateTime(year, month, i);
sbDays.Append(i.ToString() + "\t ");
sbWeeks.Append(dt.DayOfWeek.ToString() + "\t ");
}
Console.WriteLine(sbDays.ToString());
Console.WriteLine(sbWeeks.ToString());
------解决方案--------------------
DateTime dt = new DateTime(2006,1,24);
string s = dt.ToString( "dddd ",new System.Globalization.CultureInfo( "zh-CN "));