本文介绍了使用C#从给定日期查找日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友
我需要使用日期时间来查找星期几
例如:
日期:2013-06-24
现在是第四个星期一(我需要找到这个4)
周数是5
通过使用周数功能,我得到5,
但我需要找到如何获得4作为输出
hi friends
I need to find the day of week using date time
example:
Date: 2013-06-24
it is 4th Monday ( i need to find this 4)
week number is 5
by using week number function i m getting 5,
but i need to find how can i get 4 as output
推荐答案
public static void Main()
{
DateTime dt = new DateTime(2003, 5, 1);
Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}",
dt, dt.DayOfWeek == DayOfWeek.Thursday);
Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek);
}
来自: [ ^ ]
From: MSDN[^]
class Program
{
static void Main(string[] args)
{
DateTime dt = new DateTime();
dt = DateTime.Parse("24-Jun-2013");
int d = ReturnDayCount(dt);
}
static int ReturnDayCount(DateTime inDate)
{
return (inDate.Day % 7) == 0 ? (inDate.Day / 7) : (inDate.Day / 7) + 1;
}
}
这篇关于使用C#从给定日期查找日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!