如何获得前三个日期 [英] how to get the three previous dates

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

问题描述

嗨.
我如何从当前日期获取前三个日期.例如,当前日期是2011年7月16日.所以我可以得到以前的日期(15/07/2011,14/07/2011,13/07/2011).请注意,月份也可以更改.就像日期是2011年7月1日,我想获取前三个日期,因此在这种情况下,不仅日期,而且月份都会更改.因此,请告诉我如何使用asp.net和c#

hi.
how can i get the previous three dates from the current date. for example the current date is 16/07/2011. so can i get the previous dates(15/07/2011,14/07/2011,13/07/2011).note that month can also be changed. like if date is 01/07/2011 and i want to get the previous three dates so in this case not only day but also month will be changed. so please tell me how to do this using asp.net with c#

推荐答案

尝试以下代码.

Try below code.

DateTime currentDate = System.DateTime.Now;
StringBuilder previousThreeDates = new StringBuilder();
DateTime previousDate;

for (int i = 1; i < 4; i++)
{
 previousDate = currentDate.AddDays(-i);
 previousThreeDates.Append(previousDate.ToString("dd/MM/yyyy"));
 if (i < 3)
  previousThreeDates.Append(",");
}

Response.Write(previousThreeDates.ToString());


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

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