[英]How to get date from day of year
如何在C#中获取day of year
中的date
?
我有这个代码:
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
我需要得到22.2.2014
的价值。 但这不起作用,我该怎么办? 提前致谢。
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
假设你想要今年?
int a = 53;
DateTime date = new DateTime(DateTime.Now.Year, 1,1).AddDays(a -1);
int a = 53;
var dt = new DateTime(DateTime.Now.Year, 1, 1).AddDays(a - 1);
string b = dt.ToString();
使用
DateTime.AddDays()
初始化的日期开始的一年,那么只需添加a
使用此函数来
http://msdn.microsoft.com/en-us/library/system.datetime.adddays(v=vs.110).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.