通过在from dd/MM/yyyy中插入日期来查找星期几 [英] Find day of the week by inserting date in fromat dd/MM/yyyy

查看:125
本文介绍了通过在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.


DayOfWeek是一个结构!只需使用int值,然后根据需要设置其格式.演示:

DayOfWeek is a struct! Just use the int value instead and format it as desired. Demonstration:

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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆