Instead of handling this yourself in C #, you can simply use the JulianCalendar class
And to get into the Julian calendar today, you can do:
JulianCalendar calendar = new JulianCalendar(); var today=DateTime.Today; var dateInJulian = calendar.ToDateTime(today.Year, today.Month, today.Day, today.Hour, today.Minute, today.Second, today.Millisecond);
EDIT:
And I realized that I didnβt help you with a good way to get the result in the YYJJJ format you were looking for, this is pretty simple:
var stringResult=string.Format("{0}{1}", dateInJulian.ToString("yy"), dateInJulian.DayOfYear);
Unfortunately, I do not think there is an equivalent to dateTime.ToString("JJJ");
which will give the day of the year, which means my little string.Format()
work-around, but it works just as well!
EDIT2:
So, Phog reinforced me a bit in the comments and noted that you did not look today in the Julian calendar, which was said above in relation to the JulianCalendar class. Rather, you seem to be looking for the date of the ordinal (this snippet has been added to further clarify the reader). I am going to leave above so that someone does not make the same mistake as me. I believe that you really need the code from the first edit, but without the JulianCalendar business, therefore:
var dateToConvert = DateTime.Today
Kevek source share