Get a DateTime by subtracting seconds from the current date

前端 未结 3 2223
说谎
说谎 2021-02-19 01:41

I would like to subtract seconds from a date, for example:

Lets say I have 1300 seconds in a unsigned integer, I would like to take the current date and time, subtract 1

相关标签:
3条回答
  • 2021-02-19 02:24

    Try:

    DateTime.Now.AddSeconds(-1300);
    
    0 讨论(0)
  • 2021-02-19 02:26
    DateTime.Now.AddSeconds(-1300)
    

    That was easy

    0 讨论(0)
  • 2021-02-19 02:39

    AddSeconds(double value) method of DateTime takes positive and negative number of seconds:

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

    Hence, to subtract 1300 seconds you need to add -1300 seconds:

    DateTime.Now.AddSeconds(-1300);
    
    0 讨论(0)
提交回复
热议问题