What was the date 180 days ago?

2020-06-30 05:11发布

How would I get the date 180 days ago using C#?

标签: c# date
5条回答
贼婆χ
2楼-- · 2020-06-30 05:38
DateTime oneEightyAgo = DateTime.Now.ToUniversalTime().AddDays(-180); 

Its best to record UTC...

查看更多
太酷不给撩
3楼-- · 2020-06-30 05:45

DateTime.Now.AddDays(-180)

查看更多
成全新的幸福
4楼-- · 2020-06-30 05:47

DateTime.Now.AddDays(-180)

查看更多
贪生不怕死
5楼-- · 2020-06-30 05:49
DateTime oneEightyAgo = DateTime.Today.AddDays(-180);
查看更多
劳资没心,怎么记你
6楼-- · 2020-06-30 06:02

EDIT:

DateTime day180 = Date.Now.AddDays(-180);

It's important to put it into a separate variable otherwise the value will be lost.

查看更多
登录 后发表回答