How can I convert an int
to TimeSpan
?
example 486000000000
is int
as number of ticks. I want it to be represented as TimeSpan
To convert number INT in minutes to TIME in MySQL, you can use SEC_TO_TIME() function. Insert some records in the table using insert command.
To convert a DateTime to a TimeSpan you should choose a base date/time - e.g. midnight of January 1st, 2000, and subtract it from your DateTime value (and add it when you want to convert back to DateTime ). If you simply want to convert a DateTime to a number you can use the Ticks property. Show activity on this post.
You can use the From methods, those will allow you to convert days/hours/minutes/seconds/milliseconds/ticks to TimeSpam format as follows:
TimeSpan ts = TimeSpan.FromTicks(486000000000); Console.WriteLine(ts.ToString());
You can replace FromTicks
with
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With