如何从一年中的某一天获取日期

HQt*_*izy 11 c# datetime

我怎样才能dateday of yearC#中获得?

我有这个代码:

int a = 53;   // This is the day of year value, that I got previously
string b = Convert.ToDateTime(a).ToString();   // Trying to get the date
Run Code Online (Sandbox Code Playgroud)

我需要获得价值22.2.2014.但这不起作用,我该怎么办?提前致谢.

Ash*_*way 19

int dayOfYear = 53;
int year = DateTime.Now.Year; //Or any year you want
DateTime theDate = new DateTime(year, 1, 1).AddDays(dayOfYear - 1);
string b = theDate.ToString("d.M.yyyy");   // The date in requested format
Run Code Online (Sandbox Code Playgroud)


Jos*_*son 5

假设您想要当前年份?

int a = 53;
DateTime date = new DateTime(DateTime.Now.Year, 1,1).AddDays(a -1);
Run Code Online (Sandbox Code Playgroud)