C# 如何从当前时间减去 6 小时?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13759278/
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-10 09:42:48  来源:igfitidea点击:

How can I subtract 6 hour from the current time?

c#.netdatetime

提问by markzzz

Possible Duplicate:
c#: whats the easiest way to subtract time?

可能的重复:
c#:减时间最简单的方法是什么?

Suppose I have this time :

假设我有这个时间:

07/12/2012 - 00:30:45 

I'd like to subtract 6 hour, such as 06/12/2012 - 18:30:45. I see there are .AddHours() but not SubHours(). How can I do it?

我想减去 6 小时,例如 06/12/2012 - 18:30:45。我看到有 .AddHours() 但没有 SubHours()。我该怎么做?

采纳答案by Adil

You can use AddHours, it will subtract hours if negative number is passed.

您可以使用AddHours,如果传递负数,它将减去小时数。

DateTime dt1 = dt.AddHours(-6);

回答by Wim Ombelets

You can use negative values to subtract time

您可以使用负值来减去时间

myTime.AddHours(-6);