{"id":381,"date":"2023-08-12T10:16:31","date_gmt":"2023-08-12T16:16:31","guid":{"rendered":"https:\/\/kop.lat\/blog\/?p=381"},"modified":"2023-08-21T12:02:47","modified_gmt":"2023-08-21T18:02:47","slug":"time-measurement-in-c-timespans","status":"publish","type":"post","link":"https:\/\/kop.lat\/blog\/time-measurement-in-c-timespans\/","title":{"rendered":"Time measurement in C# (TimeSpans)"},"content":{"rendered":"\n<p>let&#8217;s say you would like to measure the time from 1 point in time to another.<\/p>\n\n\n\n<p>The solution is to use TimeSpan in C#<\/p>\n\n\n\n<p>Like this:<\/p>\n\n\n\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\" snippet-height=\"\" style=\"background-color:#abb8c3\"><div class=\"control-language\"><div class=\"dm-buttons\"><div class=\"dm-buttons-left\"><div class=\"dm-button-snippet red-button\"><\/div><div class=\"dm-button-snippet orange-button\"><\/div><div class=\"dm-button-snippet green-button\"><\/div><\/div><div class=\"dm-buttons-right\"><a id=\"dm-copy-raw-code\"><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span><span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a><\/div><\/div><pre class=\" no-line-numbers\"><code id=\"dm-code-raw\" class=\" no-wrap language-clike\">            var timeSpan1 = new TimeSpan(1, 2, 3); \/\/ 1 hour 2 min 3 secs\n\n            var start1 = DateTime.Now; \/\/ get the actual time\n            var end1 = DateTime.Now.AddMinutes(2); \/\/ Add 2 minuts\n            var duration1 = end1 - start1; \/\/ duration is the difference between the 2 timespans\n\n           <\/code><\/pre><\/div><\/div>\n\n\n\n<p>Basically duration1, is a timeSpan that contains the difference between 2 different times, in this case is only 2 minutes, just to show the example. <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>let&#8217;s say you would like to measure the time from 1 point in time to another. The solution is to use TimeSpan in C# Like this: Basically duration1, is a timeSpan that contains the difference between 2 different times, in this case is only 2 minutes, just to show the example.<\/p>\n","protected":false},"author":2,"featured_media":257,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[41,1,51,32,52,7],"tags":[53,54,55],"_links":{"self":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/381"}],"collection":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":1,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions\/382"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/media\/257"}],"wp:attachment":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}