获得与一天相对应的日期 [英] to get date corresponding to a day
本文介绍了获得与一天相对应的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
haii ..
我希望得到与一周工作日相对应的即将到来的日期。例如:对应于即将到来的星期五的日期(dd / MM / yyyy)。所以我需要一个函数(C#).. plz help..its urgent
解决方案
如果你想从日期检索星期几你可以试试下面的方法
DateTime date = DateTime.Now;
Console.WriteLine(date.ToString( dddd));
参考如何:从特定日期提取星期几 [ ^ ]
[更新]
创建一个名为days的枚举
枚举天
{
星期日,
星期一,
周二,
周三,
thrusday,
周五,
周六,
};
然后,您可以使用此枚举值作为输入参数,并使用以下逻辑检索工作日的日期。
工作日= Days.sunday ;
DateTime Today = DateTime.Today;
DateTime finalDate;
if (( int )Today.DayOfWeek < ( int )工作日)
{
finalDate = Today.Date.AddDays(( int )工作日 - ( int )Today.DayOfWeek);
}
else
{
finalDate = Today.Date.AddDays(( int )工作日 - ( int )Today.DayOfWeek + 7 );
}
[/ Update]
亲爱的,
我想你需要''星期五 - 12月 - 2012''。
例如:
dateTimePicker1.CustomFormat = System.DateTime.Today.ToString(dddd-MMMM-yyyy);
如果你喜欢这个答案plz vote我
嗨亲爱的,
string 天= 星期五; // 星期五是工作日
string dayName = dateTimePicker1.Value.DayOfWeek.ToString();
if (Days == dayName)
{
// 工作日
}
其他
{
// 非工作日
}
haii..
I want to get the upcoming date corresponding to a week day. Eg: The date(dd/MM/yyyy) corresponding to coming Friday. So I need a function (C#)..plz help..its urgent
解决方案
If you looking to retrieve the day of week from date you can try the below approach
DateTime date = DateTime.Now; Console.WriteLine(date.ToString("dddd"));
Refer How to: Extract the Day of the Week from a Specific Date[^]
[Update]
Create an enum called days
enum Days { sunday, monday, tuesday, wednesday, thrusday, friday, saturday, };
You can then use this enum value as a input parameter and retrieve the date of week day using the below logic.
Days weekday = Days.sunday; DateTime Today = DateTime.Today; DateTime finalDate; if ((int)Today.DayOfWeek < (int)weekday) { finalDate = Today.Date.AddDays((int)weekday - (int)Today.DayOfWeek); } else { finalDate = Today.Date.AddDays((int)weekday - (int)Today.DayOfWeek + 7); }
[/Update]
Hi dear,
I think you need ''Friday - December - 2012''.
Example :
dateTimePicker1.CustomFormat = System.DateTime.Today.ToString("dddd-MMMM-yyyy");
If you like this answer plz vote me
hi dear,
string Days = "Friday"; // Friday is week day string dayName = dateTimePicker1.Value.DayOfWeek.ToString(); if (Days == dayName) { // week day } else { // Not week day }
这篇关于获得与一天相对应的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文