0

How can I convert javascript time string of

var time="10:15:00";

to C# timespan property like:

public System.TimeSpan Hours { get; set; }

I'll pass it as JSON by using ajax call to MVC method. However, the type of property must be the same henve I'll only show the time with the format "hh:mm:ss" as timespan.

  • use TimeSpan.Parse(string) method – miechooy Apr 27 '18 at 08:08
  • This is C# pased. I'm looking for a function to convert from Javascript string to C# TimeSpan type! – Daniel Fellner Apr 27 '18 at 09:16
  • The right string format (that will be parsed into C# TimeSpan) is: {Days}:{Hours}:{Minutes}:{Seconds}.{Milliseconds} So for example, the following string: 01:02:03:04.05 will be parsed into TimeSpan with the following details: 1:Days, 2Hours, 3:Minutes, 4:Seconds, 5:Milliseconds. Please note the colon separators between all the time formats except the milliseconds which is a single dot. – Jacob Mar 31 '21 at 02:27

0 Answers0