如何找到星期几 [英] How to find the day of week

查看:109
本文介绍了如何找到星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找一周的天数。在下面的代码中,变量'daynumber'是

只显示零。在Web表单变量'daynumber'工作。所以我在窗口形式中复制了

整个事物,但'daynumber'变量只显示为零。如何纠正代码?

I want to find the day number of a week. In the following code the variable 'daynumber' is
showing just zero.In web form variable 'daynumber' works. So I copied
the entire thing in window forms but the 'daynumber' variable shows just zero. How to rectify the code?

DateTime v_todaydt = DateTime.Today;
v_DespatchDate = v_todaydt.AddDays(7).Date.ToString("yyyy/MM/dd");
DateTime dateTime = DateTime.ParseExact(v_DespatchDate, "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture);
var daynumber = ((int)dateTime.DayOfWeek);

推荐答案

Quote:

DayOfWeek枚举范围中常量的值从DayOfWeek.Sunday到DayOfWeek.Saturday。如果转换为整数,其值的范围从零(表示DayOfWeek.Sunday)到六(表示DayOfWeek.Saturday)。

The value of the constants in the DayOfWeek enumeration ranges from DayOfWeek.Sunday to DayOfWeek.Saturday. If cast to an integer, its value ranges from zero (which indicates DayOfWeek.Sunday) to six (which indicates DayOfWeek.Saturday).



阅读 DateTime的备注部分.DayOfWeek Property [ ^ ]



如果您需要一周的日期数


Read the Remarks section of the DateTime.DayOfWeek Property[^]

if you need Day number of the week

var daynumber = ((int)dateTime.DayOfWeek) +1;





备注:你的代码可以减少到



Side Note: Your code can reduce to

int dayNum = (int)DateTime.Today.AddDays(7).DayOfWeek + 1;


DayOfWeek 是一个枚举。

阅读 http:// msdn。 microsoft.com/en-us/library/system.datetime.dayofweek%28v=vs.110%29.aspx [ ^ ]。
DayOfWeek is an enumeration.
Go through the example at http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek%28v=vs.110%29.aspx[^].


这篇关于如何找到星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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