开发者

Most efficient way to find next 13rd Friday using programming [duplicate]

This question already has answers here: 开发者_StackOverflow社区 Closed 11 years ago.

Possible Duplicate:

Calculating future occurences of Friday the 13th

As i sip my beer and get bored, that question came into my mind. How could find the next 13rd Friday efficiently using popular programming languages like C, Java, C#, Python, Perl, PHP even Lisp, ALGOL etc. Which code does seem shortest and smarter?


many ways. Heres one. Note I didn't check if it parsed but the idea is right.

C#:

DateTime date = DateTime.Now; // as today is 13th. If system date changes then hardcode date.

while (date < <Some date in the future you want to report to>)
{
date = date.AddMonths(1);
if (date.DayOfWeek == DayOfWeek.Friday)
System.Console.PrintLine(date.ToString());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜