如何在asp.net C#中声明以前的日期 [英] How to declare previous dates in asp.net C#
本文介绍了如何在asp.net C#中声明以前的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在asp.net c中声明以前的日期#
这是我今天和次日的代码。
How to declare previous dates in asp.net c#
This is my code for todays and the nextday.
DateTime currentDay = DateTime.Now.Date;
DateTime nextDay = DateTime.Now.Date.AddDays(1);
现在我想宣布以前日期的代码
请帮助我谢谢。
NOW I want to declare the code for previous dates
Please help me thanks.
推荐答案
文档 [ ^ ]表示值
参数可以是正数也可以是负数。所以DateTime.Now.Date.AddDays(-1)
是你的答案。
The documentation[^] says that thevalue
parameter can be both positive and negative. SoDateTime.Now.Date.AddDays(-1)
is your answer.
尝试如下。
Try is as below.
DateTime d1 = DateTime.Now;
d1 = d1.AddDays(-1); // assign back to see the new instance
这篇关于如何在asp.net C#中声明以前的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文