﻿
{"id":4605,"date":"2016-06-28T04:17:08","date_gmt":"2016-06-28T04:17:08","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=4605"},"modified":"2016-06-28T04:17:08","modified_gmt":"2016-06-28T04:17:08","slug":"c-timespan-ile-sure-formatlama","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-timespan-ile-sure-formatlama\/","title":{"rendered":"C# TimeSpan \u0130le S\u00fcre Formatlama"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bu i\u00e7eri\u011fimizde sizlere C#&#8217;ta DateTime yap\u0131s\u0131ndan farkl\u0131 olan ve elimizdeki bir de\u011fere g\u00f6re s\u00fcre tutmam\u0131z\u0131 sa\u011flayan TimeSpan tipinden bahsedece\u011fim.<\/p>\n<p>TimeSpan, DateTime gibi struct(yap\u0131) olarak tasarlanm\u0131\u015f bir s\u00fcre temsil eden de\u011fi\u015fkendir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            TimeSpan time = new TimeSpan(3, 2, 17, 1, 12);\r\n            Console.WriteLine(time);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p>Yukar\u0131daki \u00f6rnek kod blo\u011funu incelerseniz e\u011fer 3 g\u00fcn, 2 saat, 17 dakika, 1 saniye ve 12 milisaniye olarak bir s\u00fcre tutabilir ve a\u015fa\u011f\u0131daki gibi sonu\u00e7 alabiliriz.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4606 size-full\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"556\" height=\"66\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama.jpg 556w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-300x36.jpg 300w\" sizes=\"auto, (max-width: 556px) 100vw, 556px\" \/><\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            TimeSpan time1 = TimeSpan.FromDays(5);\r\n            TimeSpan time2 = TimeSpan.FromHours(4);\r\n            TimeSpan time3 = TimeSpan.FromMinutes(3);\r\n            TimeSpan time4 = TimeSpan.FromSeconds(2);\r\n            TimeSpan time5 = TimeSpan.FromMilliseconds(1);\r\n            TimeSpan time6 = TimeSpan.FromTicks(10);\r\n\r\n            Console.WriteLine(time1);\r\n            Console.WriteLine(time2);\r\n            Console.WriteLine(time3);\r\n            Console.WriteLine(time4);\r\n            Console.WriteLine(time5);\r\n            Console.WriteLine(time6);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p>Yukar\u0131daki \u00f6rnek kod blo\u011funun \u00e7\u0131kt\u0131s\u0131 ise a\u015fa\u011f\u0131daki gibi olacakt\u0131r.<br \/>\n<span style=\"color: #ff0000;\"><em><strong>FromDays<\/strong><\/em><\/span> g\u00fcn, <span style=\"color: #ff0000;\"><em><strong>FromHours<\/strong><\/em><\/span> saat, <span style=\"color: #ff0000;\"><em><strong>FromMinutes<\/strong><\/em><\/span> dakika, <span style=\"color: #ff0000;\"><em><strong>FromSeconds<\/strong><\/em><\/span> saniye ve <span style=\"color: #ff0000;\"><em><strong>FromMilliseconds<\/strong><\/em><\/span> milisaniye eklemek i\u00e7indir.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4608\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-1.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"167\" height=\"142\" \/><\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            TimeSpan time1 = TimeSpan.FromDays(5);\r\n            TimeSpan time2 = TimeSpan.FromHours(4);\r\n            TimeSpan time3 = TimeSpan.FromMinutes(3);\r\n            TimeSpan time4 = TimeSpan.FromSeconds(2);\r\n            TimeSpan time5 = TimeSpan.FromMilliseconds(1);\r\n            TimeSpan time6 = TimeSpan.FromTicks(10);\r\n\r\n            TimeSpan time7 = time1.Add(time2).Add(time3).Add(time4).Add(time5).Add(time6);\r\n\r\n            Console.WriteLine(time7);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p>Bu \u015fekilde <span style=\"color: #ff0000;\"><em><strong>Add<\/strong><\/em><\/span> metodu kullan\u0131larak elimizdeki mevcut s\u00fcreye herhangi bir zaman kavram\u0131n\u0131 ekleyebilmekteyiz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4609\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-2.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"185\" height=\"66\" \/><\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            TimeSpan time1 = TimeSpan.FromDays(5);\r\n            TimeSpan time2 = TimeSpan.FromMinutes(4);\r\n            TimeSpan time3 = time1.Subtract(time2);\r\n            Console.WriteLine(time3);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p><span style=\"color: #ff0000;\"><em><strong>Subtract<\/strong><\/em><\/span> metodu sayesinde iki s\u00fcre aras\u0131ndaki fark\u0131 bulabilmekteyiz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-3.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"117\" height=\"60\" class=\"aligncenter size-full wp-image-4612\" \/><\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            Console.WriteLine(TimeSpan.MaxValue);\r\n            Console.WriteLine(TimeSpan.MinValue);\r\n            Console.WriteLine(TimeSpan.Zero);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p><span style=\"color: #ff0000;\"><em><strong>MaxValue<\/strong><\/em><\/span>, <span style=\"color: #ff0000;\"><em><strong>MinValue<\/strong><\/em><\/span> ve <span style=\"color: #ff0000;\"><em><strong>Zero<\/strong><\/em><\/span> propertyleri ile s\u0131ras\u0131yla TimeSpan&#8217;\u0131n alabilece\u011fi en b\u00fcy\u00fck, en k\u00fc\u00e7\u00fck ve s\u0131f\u0131rlanm\u0131\u015f de\u011ferleri elde edebilmekteyiz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-4.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"255\" height=\"82\" class=\"aligncenter size-full wp-image-4615\" \/><\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            Console.WriteLine(TimeSpan.TicksPerDay);\r\n            Console.WriteLine(TimeSpan.TicksPerHour);\r\n            Console.WriteLine(TimeSpan.TicksPerMinute);\r\n            Console.WriteLine(TimeSpan.TicksPerSecond);\r\n            Console.WriteLine(TimeSpan.TicksPerMillisecond);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p>TimeSpan tiklerden olu\u015ftu\u011fu i\u00e7in <span style=\"color: #ff0000;\"><em><strong>TicksPerDay<\/strong><\/em><\/span> ile her g\u00fcn\u00fcn, <span style=\"color: #ff0000;\"><em><strong>TicksPerHour<\/strong><\/em><\/span> ile her saatin, <span style=\"color: #ff0000;\"><em><strong>TicksPerMinute<\/strong><\/em><\/span> ile her dakikan\u0131n, <span style=\"color: #ff0000;\"><em><strong>TicksPerSecond<\/strong><\/em><\/span> ile her saniyenin ve <span style=\"color: #ff0000;\"><em><strong>TicksPerMillisecond<\/strong><\/em><\/span> ile her milisaniyenin ka\u00e7 tikten olu\u015ftu\u011funu g\u00f6rebiliriz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-5.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-5.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"124\" height=\"127\" class=\"aligncenter size-full wp-image-4619\" \/><\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            TimeSpan time1 = new TimeSpan(-1, -1, -25, -1, -1);\r\n            Console.WriteLine(time1.Duration());\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p><span style=\"color: #ff0000;\"><em><strong>Duration<\/strong><\/em><\/span> metodu ile elimizdeki zaman\u0131n mutlak de\u011ferini alabiliriz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-6.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-6.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"163\" height=\"54\" class=\"aligncenter size-full wp-image-4622\" \/><\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            TimeSpan time1 = new TimeSpan(3, 5, 7, 8, 9);\r\n            Console.WriteLine(&quot;G\u00fcn = &quot; + time1.Days);\r\n            Console.WriteLine(&quot;Kalan G\u00fcn = &quot; + time1.TotalDays);\r\n            Console.WriteLine(&quot;Saat = &quot; + time1.Hours);\r\n            Console.WriteLine(&quot;Kalan Saat = &quot; + time1.TotalHours);\r\n            Console.WriteLine(&quot;Dakika = &quot; + time1.Minutes);\r\n            Console.WriteLine(&quot;Kalan Dakika = &quot; + time1.TotalMinutes);\r\n            Console.WriteLine(&quot;Saniye = &quot; + time1.Seconds);\r\n            Console.WriteLine(&quot;Kalan Saniye = &quot; + time1.TotalSeconds);\r\n            Console.WriteLine(&quot;Mili Saniye = &quot; + time1.Milliseconds);\r\n            Console.WriteLine(&quot;Kalan Mili Saniye = &quot; + time1.TotalMilliseconds);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p>Yukar\u0131daki kod blo\u011funu incelerseniz eldeki s\u00fcrenin nicel olarak kavramsal zaman\u0131yla birlikte, toplam yani kalan zaman\u0131n\u0131da hesaplayabilmekteyiz. \u00c7a\u011f\u0131rd\u0131\u011f\u0131n\u0131z kavram\u0131n Total.. ile ba\u015flayan propertysi toplam\u0131 vermektedir.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-7.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/C-TimeSpan-\u0130le-S\u00fcre-Formatlama-7.jpg\" alt=\"C# TimeSpan \u0130le S\u00fcre Formatlama\" width=\"292\" height=\"181\" class=\"aligncenter size-full wp-image-4624\" \/><\/a><\/p>\n<p>Evet, TimeSpan struct\u0131 ile yukar\u0131daki zamansal i\u015flemlerin hepsini performansl\u0131 bir \u015fekilde ger\u00e7ekle\u015ftirebilirsiniz.<\/p>\n<p>Sonraki yaz\u0131lar\u0131m\u0131zda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bu i\u00e7eri\u011fimizde sizlere C#&#8217;ta DateTime yap\u0131s\u0131ndan farkl\u0131 olan ve elimizdeki bir de\u011fere g\u00f6re s\u00fcre tutmam\u0131z\u0131 sa\u011flayan TimeSpan tipinden bahsedece\u011fim. TimeSpan, DateTime gibi struct(yap\u0131) olarak tasarlanm\u0131\u015f bir s\u00fcre temsil eden de\u011fi\u015fkendir. static void Main(string&#x5B;]&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":3014,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[1277,507,1293,1292,1281,1282,1285,1283,1284,1286,1295,1278,1301,1297,1279,1299,1276,1287,1289,1291,1288,1290,1275,1294,1296,1302,1298,1300,1280],"class_list":["post-4605","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","tag-add","tag-datetime","tag-days","tag-duration","tag-fromdays","tag-fromhours","tag-frommilliseconds","tag-fromminutes","tag-fromseconds","tag-fromticks","tag-hours","tag-maxvalue","tag-milliseconds","tag-minutes","tag-minvalue","tag-seconds","tag-subtract","tag-ticksperday","tag-ticksperhour","tag-tickspermillisecond","tag-ticksperminute","tag-tickspersecond","tag-timespan","tag-totaldays","tag-totalhours","tag-totalmilliseconds","tag-totalminutes","tag-totalseconds","tag-zero"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=4605"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4605\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3014"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=4605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=4605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=4605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}