Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add seconds to Time in C#? [closed]

Tags:

c#

How to add seconds to Time which is in hours:min:sec format in c#???

Example: I want to add seconds-5678 to hours:min:sec and then display the result...

like image 612
srinivas Avatar asked Oct 19 '25 03:10

srinivas


2 Answers

You can use AddSeconds, like

DateTime.Now.AddSeconds(5678)
like image 81
Satpal Avatar answered Oct 21 '25 17:10

Satpal


DateTime dt = DateTime.ParseExact("14:44:56", "HH:mm:ss", null);
string result = dt.AddSeconds(5678 ).ToString("HH:mm:ss"); // 16:19:34

Demo

like image 25
Tim Schmelter Avatar answered Oct 21 '25 15:10

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!