Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert integer to timespan [closed]

Tags:

c#

How can I convert an int to TimeSpan?

example 486000000000 is int as number of ticks. I want it to be represented as TimeSpan

like image 499
Jack Manson Avatar asked Mar 23 '13 08:03

Jack Manson


People also ask

How do you convert int to time?

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.

How do I convert datetime to TimeSpan?

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.


1 Answers

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

  • FromDays
  • FromHours
  • FromMilliseconds
  • FromMinutes
  • FromSeconds
  • FromTicks
like image 148
coolmine Avatar answered Oct 13 '22 06:10

coolmine