开发者

C# - How to calculate the current day-of-year?

Today is 5.27.2010 - this means it is da开发者_Go百科y 147 of this year.

How do I calculate that today is 147 based on the current date?


There's a DateTime property named just that: DayOfYear

Console.WriteLine(DateTime.Now.DayOfYear);

Or for any date:

var d = new DateTime(2010, 5, 30);
Console.WriteLine(d.DayOfYear);


Actually, it's pretty easy:

int dayOfYear = DateTime.Today.DayOfYear;


C#'s DateTime class has a method called DayOfYear() that you could use.


Has anyone mentioned the DateTime.DayOfYear property?


DateTime dt = new DateTime(2001, 12, 14);
            dynamic dayofyear = dt.DayOfYear;
            dynamic datofweek = dt.DayOfWeek;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜