gpt4 book ai didi

c# - 通过从当前日期减去秒数获得 DateTime

转载 作者:可可西里 更新时间:2023-11-01 03:13:25 27 4
gpt4 key购买 nike

我想从日期中减去秒数,例如:

假设我有 1300 秒的无符号整数,我想用当前日期和时间减去 1,300 秒,最后得到:

01/13/2012 2:15 PM(格式并不重要)。

我试过:

DateTime dt = new DateTime(); 
dt.Add(new TimeSpan(0, 0, ui.OnlineTime));
Online.Text = dt.ToLongDateString();

最佳答案

AddSeconds(double value) DateTime 方法取正负秒数:

[value parameter represents] a number of whole and fractional seconds. The value parameter can be negative or positive.

因此,要减去 1300 秒,您需要添加 -1300 秒:

DateTime.Now.AddSeconds(-1300);

关于c# - 通过从当前日期减去秒数获得 DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8858683/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com