积极答复者
怎么得到指定日期的前5天,考虑闰年。

问题
-
比如我输入string=“20090801“
如何才能得到包含指定日期以及此前5天日期的字符数组呢?
就是得到20090801 20080731 20090731 20090729 20090728 20090727
- 已移动 Sheng Jiang 蒋晟Moderator 2011年8月8日 2:44 System.DateTime (发件人:Visual C#)
答案
-
string sDateTime = "20090801"; IFormatProvider ifp = new System.Globalization.CultureInfo("zh-cn", true); DateTime dateTime = DateTime.ParseExact(sDateTime, "yyyyMMdd", ifp); string[] sDateList = new string[6]; for (int i = 0; i < 6; i++) { sDateList[i] = dateTime.AddDays(-i).ToString("yyyyMMdd"); }
歡迎參觀我的Blog.NET菜鳥自救會
- 已标记为答案 suelincl 2011年8月8日 7:49
全部回复
-
DateTime.TryPrase
DateTime,AddDays
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
string sDateTime = "20090801"; IFormatProvider ifp = new System.Globalization.CultureInfo("zh-cn", true); DateTime dateTime = DateTime.ParseExact(sDateTime, "yyyyMMdd", ifp); string[] sDateList = new string[6]; for (int i = 0; i < 6; i++) { sDateList[i] = dateTime.AddDays(-i).ToString("yyyyMMdd"); }
歡迎參觀我的Blog.NET菜鳥自救會
- 已标记为答案 suelincl 2011年8月8日 7:49