c# - 将小时/分钟添加到 C# 中的日期时间变量

标签 c# datetime

这个问题在这里已经有了答案:





Add hours or minutes to the current time

(4 个回答)


4年前关闭。




我想将 30 分钟添加到我的日期时间变量。
我的代码:

string time = ViewState["CloseTime"].ToString();
DateTime Closetime = DateTime.ParseExact(time, "HH:mm:ss", CultureInfo.InvariantCulture);
这里我的日期时间变量是 Closetime。我想增加 30 分钟。这怎么可能?

最佳答案

用:

DateTime currentTime = DateTime.Now;
DateTime x30MinsLater = currentTime.AddMinutes(30);
Console.WriteLine(string.Format("{0} {1}", currentTime, x30MinsLater));
结果:
4/11/2017 3:53:20 PM 4/11/2017 4:23:20 PM

关于c# - 将小时/分钟添加到 C# 中的日期时间变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43339763/

相关文章:

c# - Linq 联盟 : How to add a literal value to the query?

python - 日期时间中每 10 分钟绘制一次

c# - 忽略时区偏移

python - 按星期几查找下一个日期

c# - 识别未使用的类/控件/页面

c# - 将 VisualStateGroup 的当前状态绑定(bind)到 UWP MVVM 应用中 View 模型中的属性

c# - 如何在 ItemsControl 中的项目之间添加分隔符

c# - 在移动应用程序中使用 ApiController

python - 如何汇总每 5 秒的每一列时间序列数据

python - pandas 中日期时间系列的增量属性