如何获得在C#昨天和明天的日期时间 [英] how get yesterday and tomorrow datetime in c#

查看:1262
本文介绍了如何获得在C#昨天和明天的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码:

int MonthNow = System.DateTime.Now.Month;
int YearNow = System.DateTime.Now.Year;
int DayNow = System.DateTime.Now.Day;



我如何能得到昨天和明天的日子,月和年在C#中?

How can I get yesterday and tomorrow day, month and year in C#?

当然,我可以只写:

DayTommorow = DayNow +1;



但它可能发生,明天是其他的一个月或一年。是否有内置的工具来找出昨天和今天C#?

but it may happen that tomorrow is other month or year. Are there in C# built-in tools to find out yesterday and today?

推荐答案

您可以找到这些信息就在API参考。

You can find this info right in the API reference.

的http:// MSDN .microsoft.com / EN-US /库/ system.datetime.adddays.aspx

today = System.DateTime.Now
      answer  = today.AddDays(36)
      answer2 = today.AddDays(-36)

这篇关于如何获得在C#昨天和明天的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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