datetime - How to find difference between 2 time strings in HHMMSSmmmuuu format in C# -
i have 2 time strings in hh:mm:ss:mmm:uuu format. how find difference (time span) between them?
string t1="06:37:30:210:111"; string t2="06:38:32:310:222"; i want find difference (in terms of time) between t2 , t1 (t2-t1).
how this?
try this:
class program { static void main(string[] args) { string t1 = "06:37:30:210:111"; string t2 = "06:38:32:310:222"; var tp1 = timespan.parseexact( t1.remove(t1.lastindexof(":")), @"hh\:mm\:ss\:ffffff", cultureinfo.invariantculture); var tp2 = timespan.parseexact( t2.remove(t2.lastindexof(":")), @"hh\:mm\:ss\:ffffff", cultureinfo.invariantculture); console.writeline(tp2 - tp1); } }
Comments
Post a Comment