使用C#从给定日期查找日期 [英] Find day from the given date using c#

查看:195
本文介绍了使用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

推荐答案

尝试以下方法:
Try this:
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[^]


Get the correct week number of a given date[^] Hope this will give you more info.


尝试一下,希望这可以解决您的问题

Try this, hopefully this should solve your problem

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#从给定日期查找日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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