本文介绍了通过在from dd/MM/yyyy中插入日期来查找星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想通过插入日期来获取星期几,但使用格式dd/MM/yyyy

现在这就是我所做的..

< pre lang ="c#"> Session ["StartDate"] = 09/10/2011
字符串ddMMyyyyFormat = Session ["StartDate"].ToString();//dd/MM/yyyy中的日期
字符串MMddyyyFormat = Convert.ToDateTime(ddMMyyyyFormat).ToString("MM/dd/yyyy");

DateTime MMddyyyyDate = Convert.ToDateTime(MMddyyyFormat);
字符串dayOfWeek = MMddyyyyDate.DayOfWeek.ToString();</pre>

现在,我将星期几作为星期六",因为它没有转换为MM/dd/yyyy

Hi guys

I want to get day of the week by inserting the date but using format dd/MM/yyyy

Now this is what i did..

<pre lang="c#">Session["StartDate"]=09/10/2011
string ddMMyyyyFormat = Session["StartDate"].ToString();//Date in dd/MM/yyyy
string MMddyyyFormat =Convert.ToDateTime(ddMMyyyyFormat).ToString("MM/dd/yyyy");

DateTime MMddyyyyDate = Convert.ToDateTime(MMddyyyFormat);
string dayOfWeek = MMddyyyyDate.DayOfWeek.ToString();</pre>

Now i get the day of the week as "Saturday" because its not converted to format MM/dd/yyyy

推荐答案

session["StartDate"] = 09/10/2011;
string abc = Session["StartDate"].ToString();
DateTime xyz = Convert.ToDateTime(abc);
string dayofweek = xyz.DayOfWeek.toString()





this is working on my machine.


Console.WriteLine("{0:00}", (int)DateTime.Now.DayOfWeek);


这篇关于通过在from dd/MM/yyyy中插入日期来查找星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:45