Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中,Get Weekday Month从开始显示一个错误的日期_C#_Date_Datetime Format - Fatal编程技术网

C# 在c中,Get Weekday Month从开始显示一个错误的日期

C# 在c中,Get Weekday Month从开始显示一个错误的日期,c#,date,datetime-format,C#,Date,Datetime Format,我创建了一个函数来获取一周中的某一天,但是发生了一些奇怪的事情。检查Class_Global.cs中的以下代码 public static string GetWeekdayMonthStartsOn(int iMonth, int iYear) { var FirstDay = new DateTime(iYear, iMonth, 1); int day = (int)FirstDay.DayOfWeek; // just to test HttpConte

我创建了一个函数来获取一周中的某一天,但是发生了一些奇怪的事情。检查Class_Global.cs中的以下代码

public static string GetWeekdayMonthStartsOn(int iMonth, int iYear)
{
    var FirstDay = new DateTime(iYear, iMonth, 1);
    int day = (int)FirstDay.DayOfWeek;

    // just to test
    HttpContext.Current.Response.Write("Date=[" + FirstDay + "]<br>");
    HttpContext.Current.Response.Write("int day of week=[" + day + "]<br>");
    HttpContext.Current.Response.Write("FirstDay Week Name=[" + FirstDay.ToString("dddd") + "]<br>");
    HttpContext.Current.Response.Write("FirstDay Month Name=[" + FirstDay.ToString("MMMM") + "]<br>");

    return day.ToString ();
}
它返回下面的命令,看起来是ok。请注意,2016年3月的第一天应该是周二,而不是周一

第一天=[1/1/2106 12:00:00 AM]
第二天=[5]
第二天=[周五]
day=[一月]
第一天=[2/1/2106 12:00:00 AM]
day=[1]
day=[星期一]
day=[二月]
第一天=[3/1/2106 12:00:00 上午]
日=[1]
日=[星期一]
日=[三月]
第一天=[4/1/2106 12:00:00 AM]
天=[4]
天=[周四]
日期=[4月]
第一天=[5/1/2106 12:00:00 AM]
日期=[6]
日期=[星期六]
日期=[五月]


如果有人能帮助我,我将不胜感激。

但是3月1日,2106是星期一(见:)。

2106!=2016年-看看你的代码,我就知道了!!谢谢!!
    Class_Agenda.GetWeekdayMonthStartsOn(1, 2106);
    Class_Agenda.GetWeekdayMonthStartsOn(2, 2106);
    Class_Agenda.GetWeekdayMonthStartsOn(3, 2106);
    Class_Agenda.GetWeekdayMonthStartsOn(4, 2106);
    Class_Agenda.GetWeekdayMonthStartsOn(5, 2106);