如何减去一年,从日期时间 [英] How to subtract one year from DateTime
本文介绍了如何减去一年,从日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在窗口的一个按钮窗体应用程序(C#)来显示正好1过去一年里的时间日期和时间(特别时刻)...
示例:如果日期现在时间是二零一三年八月二十零日下午2:15
所以当我按一下按钮,它会告诉我二零一二年八月二十〇日下午2:15
...在以前的第2按键即当前的日期和时间一小时
代码我对面使用只是对昨天的日期
字符串结果= DateTime.Today.AddDays(-1)的ToString(YYYY-MM- DD);
解决方案
日期时间。 Today.AddYears(-1)的ToString(YYYY-MM-DD HH:MM:SS)
I want a button in windows forms application(C#) to display a exactly 1 year past time date and hour("specially hour")...
Example: if the date time now is 20 Aug 2013 2:15 pm
so when I click on the button, it will show me 20 Aug 2012 2:15 pm
... and opposite in 2nd button i.e from previous to current date time hour
Code I am using is just for yesterdays date
string result = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd");
解决方案
DateTime.Today.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss")
这篇关于如何减去一年,从日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文