Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime Format Day of Year

Tags:

c#

datetime

Is there a format value for DateTime.ToString("") that will specify the day of the year in three digits?

For example:

  • Jan 1, 2012 would be 001
  • Feb 1, 2012 would be 032
  • Dec 31, 2012 would be 366 (leap year)
  • Dec 31, 2011 would be 365
like image 730
Dismissile Avatar asked Mar 09 '12 19:03

Dismissile


People also ask

What is TT time format?

Terrestrial Time (TT) is a modern astronomical time standard defined by the International Astronomical Union, primarily for time-measurements of astronomical observations made from the surface of Earth.

What is T and Z in datetime?

The T is just a literal to separate the date from the time, and the Z means “zero hour offset” also known as “Zulu time” (UTC). If your strings always have a “Z” you can use: SimpleDateFormat format = new SimpleDateFormat( “yyyy-MM-dd'T'HH:mm:ss).


1 Answers

No, you can use DateTime.DayOfYear.ToString("000");

Your examples:

new DateTime(2012, 1, 1).DayOfYear.ToString("000");
new DateTime(2012, 2, 1).DayOfYear.ToString("000");
new DateTime(2012, 12, 31).DayOfYear.ToString("000");
new DateTime(2011, 12, 31).DayOfYear.ToString("000");
like image 181
David Morton Avatar answered Oct 11 '22 08:10

David Morton