如何找到第三个星期五在一个月内用C#? [英] How to find the 3rd Friday in a month with C#?

查看:272
本文介绍了如何找到第三个星期五在一个月内用C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个日期,如何找到(类的DateTime )的第三个周五在该日期的月份?

Given a date (of type DateTime), how do I find the 3rd Friday in the month of that date?

推荐答案

我没有测试过这一点,但由于第三个星期五不可能在本月15日之前发生的,创建一个新的日期时间,然后就开始递增,直到你到了周五。

I haven't tested this, but since the third Friday can't possibly occur before the 15th of the month, create a new DateTime, then just increment until you get to a Friday.

DateTime thirdFriday= new DateTime(yourDate.Year, yourDate.Month, 15);

while (thirdFriday.DayOfWeek != DayOfWeek.Friday)
{
   thirdFriday = thirdFriday.AddDays(1);
}

这篇关于如何找到第三个星期五在一个月内用C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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