Given a date (of type DateTime
), how do I find the 3rd Friday in the month of that date?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
I pass this the DateTime for the start of the month I am looking at.
Slightly more optimized version:
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.
Here's my algorithm:
The counter will give you the nth Friday of the month for that date (or its upcoming Friday).
Here is my two cents... An optimized solution without unnecessary loops or tests :