如何从今年的一天获取日期 [英] How to get date from day of year

查看:110
本文介绍了如何从今年的一天获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得日期在C#年的一天?



我有这样的代码:

  int类型的= 53; //这是今年价值的一天,我得到了以前
字符串B = Convert.ToDateTime(一)的ToString(); //试图获取日期



我需要得到的值 22.2。 2014年。但是,这并不工作,我该怎么办? 。在此先感谢


解决方案

  int类型的= 53; 
INT年= DateTime.Now.Year; //或任何一年你想
的DateTime theDate =新日期时间(年,1,1).AddDays(A - 1);
字符串B = theDate.ToString(D.M.YYYY); //所要求的格式
日期


How can I get date from day of year in C#?

I have this code :

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

I need to get the value 22.2.2014. But this doesn't work, what should I do? Thanks in advance.

解决方案

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

这篇关于如何从今年的一天获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆