如何在 C# 中获得一年前的今天日​​期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1193455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 10:30:19  来源:igfitidea点击:

How do I get todays date one year ago in C#?

c#datetime

提问by JL.

How do I get todays date one year ago in C#?

如何在 C# 中获得一年前的今天日​​期?

采纳答案by Binary Worrier

Todays date one year ago would be

一年前的今天是

DateTime lastYear = DateTime.Today.AddYears(-1);

回答by CD..

DateTime.Now.AddYears(-1);

回答by AdaTheDev

DateTime.Now.AddYears(-1)

回答by bbohac

What do you mean by "last years date"?

“去年的日期”是什么意思?

If you just want the date of today minus one year, try the following:

如果您只想将今天的日期减去一年,请尝试以下操作:

    DateTime myDateTime = DateTime.Now.AddYears(-1);

I hope that is what you need.

我希望这就是你所需要的。

UPDATE:Damn, I'm way to slow it seems :(

更新:该死,我似乎要放慢速度了:(

回答by Simon

using Fluent DateTime http://fluentdatetime.codeplex.com/

使用 Fluent DateTime http://fluentdatetime.codeplex.com/

var oneYearAgo = 1.Years().Ago();