.net - C# converting number into time error -
i reading time excel file , code convert number time
string time = "1350"; datetime dt = datetime.parseexact(time, "hhmm", cultureinfo.invariantculture); string timestring = dt.tostring("h:mm tt"); console.writeline(timestring); console.read(); the problem code works fine 4 digit numbers numbers 600, 900 etc should converted 6:00 pm , 9:00 pm code throws error. there improve way solve this?
just pad them zeros prior converting datetime.
string time = "600".padleft(4, '0'); c# .net datetime
No comments:
Post a Comment