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;
精彩评论