日期功能,从当前日期减去6个月 [英] date function to subtract 6 months from current date

查看:684
本文介绍了日期功能,从当前日期减去6个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


从当前日期减去6个月的日期函数是什么?

谢谢..

Hi,
What is the date function to subtract 6 months from current date?

Thank you..

推荐答案

我认为DateTime结构的AddMonths 方法可以使用负值,如下所示
I think the AddMonths method of DateTime structure can be used with a negative value as below
DateTime today = DateTime.Now;
DateTime sixMonthsBack = today.AddMonths(-6);
Console.WriteLine (today.ToShortDateString());
Console.WriteLine (sixMonthsBack.ToShortDateString());

//Output
//5/15/2012
//11/15/2011


这篇关于日期功能,从当前日期减去6个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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