{"id":5142,"date":"2022-06-16T00:43:42","date_gmt":"2022-06-15T15:43:42","guid":{"rendered":"https:\/\/okamurax.com\/?p=5142"},"modified":"2022-06-22T15:10:39","modified_gmt":"2022-06-22T06:10:39","slug":"%e5%8b%a4%e7%b6%9a%e5%b9%b4%e6%95%b0-%e5%b9%b4%e9%bd%a2-%e4%bd%95%e5%b9%b4%e4%bd%95%e3%83%b6%e6%9c%88%e3%81%ae%e8%80%83%e3%81%88%e6%96%b9","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=5142","title":{"rendered":"C# \u52e4\u7d9a\u5e74\u6570\/\u5e74\u9f62 \u4f55\u5e74\u4f55\u30f6\u6708\u306e\u8003\u3048\u65b9"},"content":{"rendered":"<p>\u30fb\u52e4\u7d9a\u5e74\u6570<\/p>\n<p>\u7279\u306b\u5b9a\u3081\u306e\u306a\u3044\u8a08\u7b97\u306e\u5834\u5408\u3001\u7aef\u6570\u51e6\u7406\u306b\u306f\u88c1\u91cf\u304c\u3042\u308b\u3002<\/p>\n<p>\u5e74\u306e\u671f\u9593\u3092\u6c42\u3081\u308b\u5834\u5408\u3001\u4e00\u822c\u7684\u306b\u306f\u4e00\u5e74\u672a\u6e80\u306e\u7aef\u6570\u3092\u5207\u4e0a\u3052(1\u5e74+1\u65e5\u3067\u30822\u5e74)\u3068\u3059\u308b\u3053\u3068\u304c\u591a\u304f\u3001\u540c\u3058\u3088\u3046\u306b\u6708\u306e\u671f\u9593\u3092\u6c42\u3081\u308b\u5834\u5408\u306f\u30011\u30f6\u6708\u672a\u6e80\u306e\u65e5\u306e\u7aef\u6570\u3082\u5207\u4e0a\u3052\u30661\u30f6\u6708\u3068\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u3002<br \/>\n<span style=\"color: #0000ff;\">https:\/\/www.nta.go.jp\/taxes\/shiraberu\/taxanswer\/shotoku\/1420.htm<\/span><\/p>\n<p>\u305f\u3060\u3001\u65e5\u306e\u7aef\u6570\u3092\u5207\u4e0a\u3052\u305f\u3053\u3068\u306b\u3088\u308a1\u5e74\u3092\u8d85\u3048\u3066\u3057\u307e\u30442\u5e74\u306b\u306a\u308b\u3068\u3044\u3046\u3088\u3046\u306a\u8003\u3048\u65b9\u306f\u305b\u305a\u300c1\u5e74\u672a\u6e80\u306e\u7aef\u6570\u306f1\u5e74\u306b\u5207\u4e0a\u3052\u308b\u300d\u3060\u3051\u3068\u8003\u3048\u308b\u3053\u3068\u304c\u666e\u901a\u3002<\/p>\n<p>\u6708\u306e\u90e8\u5206\u306b\u3064\u3044\u3066\u306f\u3001\u5207\u4e0a\u3052(1\u65e5\u3067\u3082\u6240\u5c5e\u3057\u305f\u30891\u30f6\u6708\u3068\u3059\u308b)\u4ee5\u5916\u306b\u3082\u3001\u65e5\u4ed8\u3092\u7121\u8996\u3059\u308b\u8a08\u7b97\u65b9\u6cd5\u3082\u3042\u308b\u3002<\/p>\n<p>\u30a4\u30e1\u30fc\u30b8\u3068\u3057\u3066\u5207\u4e0a\u3052\u306f\u958b\u59cb\u6708\u3092\u6708\u521d\u306b\u3001\u7d42\u4e86\u6708\u3092\u6708\u672b\u306b\u3057\u3066\u3044\u3066\u3001\u65e5\u4ed8\u7121\u8996\u306f\u958b\u59cb\u6708\u3068\u7d42\u4e86\u6708\u3092\u540c\u3058\u65e5\u306b\u3057\u3066\u3044\u308b\u3068\u8003\u3048\u308b\u3068\u5206\u304b\u308a\u3084\u3059\u3044\u3002<\/p>\n<p>\u30fb\u5e74\u9f62<\/p>\n<p>\u5e74\u9f62\u306e\u4f55\u30f6\u6708\u306e\u90e8\u5206\u306f\u6708\u672b\u3092\u3069\u3046\u3059\u308b\u304b\u304c\u96e3\u3057\u3044\u3002\u30b7\u30f3\u30d7\u30eb\u306a\u306e\u306f\u5148\u305a\u3001<br \/>\n<span style=\"color: #0000ff;\">\u7d4c\u904e\u6708 = \u7d42\u4e86\u6708-\u958b\u59cb\u6708<br \/>\n<\/span>\u3067\u7d4c\u904e\u6708\u3092\u7b97\u51fa\u3057\u3001<br \/>\n<span style=\"color: #0000ff;\">\u7d42\u4e86\u6708\u306e\u65e5 = \u6708\u672b OR \u958b\u59cb\u6708\u306e\u65e5 &lt;= \u7d42\u4e86\u6708\u306e\u65e5<br \/>\n<\/span><span style=\"color: #0000ff;\">\u6e80\u305f\u3055\u306a\u3044\u5834\u5408\u3001<\/span><span style=\"color: #0000ff;\">\u7d4c\u904e\u6708-1\u6708<\/span><br \/>\n\u3068\u3044\u3046\u8a08\u7b97\u5f0f\u3002\u3042\u308b\u3044\u306f\u3001<br \/>\n<span style=\"color: #0000ff;\">\u7d42\u4e86\u6708\u306e\u65e5 != \u6708\u672b AND \u958b\u59cb\u6708\u306e\u65e5 &gt; \u7d42\u4e86\u6708\u306e\u65e5<br \/>\n\u6e80\u305f\u3059\u5834\u5408\u3001\u7d4c\u904e\u6708-1\u6708<\/span><\/p>\n<p><span style=\"color: #0000ff;\">\u958b\u59cb\u6708\u306e\u65e5 &lt;= \u7d42\u4e86\u6708\u306e\u65e5<\/span><br \/>\n\u3068\u3044\u3046\u90e8\u5206\u306f\u666e\u901a\u306e\u8003\u3048\u65b9\u3067\u3001<br \/>\n<span style=\"color: #0000ff;\">\u7d42\u4e86\u6708\u306e\u65e5 = \u6708\u672b<\/span><br \/>\n\u3068\u3044\u3046\u90e8\u5206\u306f\u3001\u958b\u59cb\u6708\u3001\u7d42\u4e86\u6708\u304c\u6708\u672b\u306e\u5834\u5408\u30011\/31\uff5e2\/28\u306a\u3069\u6700\u521d\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3055\u306a\u304f\u3066\u3082\u30011\u30f6\u6708\u30d7\u30e9\u30b9\u3055\u308c\u308b\u90e8\u5206\u304c\u3042\u308a\u3001\u3053\u306e\u5834\u5408\u3001\u958b\u59cb\u6708\u5074\u306f\u4f55\u65e5\u3067\u3042\u3063\u3066\u3082\u554f\u984c\u306a\u3044\u306e\u3067\u7d42\u4e86\u6708\u5074\u3060\u3051\u6708\u672b\u304b\u3069\u3046\u304b\u5224\u65ad\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u305f\u3060\u3001\u6708\u672b\u540c\u58eb\u30671\u30f6\u6708\u3068\u8003\u3048\u308b\u65b9\u304c\u81ea\u7136\u3067\u306f\u3042\u308b\u3051\u3069\u3001\u5f53\u7136\u3001<br \/>\n7\/31-8\/30\u30671\u30f6\u6708\u5224\u5b9a\u306a\u3057<br \/>\n8\/31-9\/30\u30671\u30f6\u6708\u5224\u5b9a\u3042\u308a<br \/>\n\u3068\u3044\u3046\u3088\u3046\u7d50\u679c\u3082\u3042\u308b\u306e\u3067\u5c11\u3057\u6c17\u6301\u3061\u60aa\u3055\u3082\u6b8b\u308b\u3002<\/p>\n<pre class=\"lang:c# decode:true \">using System;\r\nusing System.Windows.Forms;\r\n\r\nnamespace WindowsFormsApp1\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n            textBox1.LostFocus += DateParse;\r\n            textBox2.LostFocus += DateParse;\r\n        }\r\n\r\n        private void DateParse(object sender, EventArgs e)\r\n        {\r\n            TextBox textBox = (TextBox)sender;\r\n            try\r\n            {\r\n                textBox.Text = DateTime.Parse(textBox.Text).ToString(\"yyyy\/MM\/dd\");\r\n            }\r\n            catch\r\n            {\r\n                textBox.Text = \"\";\r\n            }\r\n            GetDuration();\r\n        }\r\n\r\n        private void GetDuration()\r\n        {\r\n            if (textBox1.Text == \"\" || textBox2.Text == \"\") return;\r\n\r\n            var startDate = DateTime.Parse(textBox1.Text);\r\n            var endDate = DateTime.Parse(textBox2.Text);\r\n\r\n            if (startDate &gt; endDate) return;\r\n\r\n            int y = endDate.Year - startDate.Year;\r\n            int m = endDate.Month - startDate.Month;\r\n\r\n            if (startDate.Month &gt; endDate.Month)\r\n            {\r\n                y = y - 1;\r\n                m = 12 + m; \/\/ m\u306f\u30de\u30a4\u30ca\u30b9\u306e\u5024\u304c\u5165\u3063\u3066\u3044\u308b\r\n            }\r\n\r\n            \/\/ \u52e4\u7d9a\u5e74\u6570(\u5207\u4e0a\u3052) --------------------------------------------------------\r\n\r\n            int yy = y;\r\n            int mm = m + 1;\r\n            if (mm == 12) \/\/ mm\u306f\u6700\u5927\u3067\u3082m=11\u3067+1\u3055\u308c12\u307e\u3067\r\n            {\r\n                yy = y + 1;\r\n                mm = 0;\r\n            }\r\n\r\n            textBox3.Text = yy.ToString() + \"\u5e74\" + mm.ToString() + \"\u30f6\u6708\";\r\n\r\n            \/\/ \u52e4\u7d9a\u5e74\u6570(\u5207\u4e0b\u3052) --------------------------------------------------------\r\n\r\n            textBox4.Text = y.ToString() + \"\u5e74\" + m.ToString() + \"\u30f6\u6708\";\r\n\r\n            \/\/ \u5e74\u9f62 --------------------------------------------------------\r\n\r\n            bool isLastDay = false;\r\n            if (endDate.Month != endDate.AddDays(1).Month) isLastDay = true; \/\/ \u6708\u672b\u304b\u3069\u3046\u304b\r\n\r\n            int yyy = y;\r\n            int mmm = m;\r\n\r\n            if (startDate.Day &gt; endDate.Day &amp;&amp; !isLastDay) mmm = m - 1;\r\n\r\n            if (mmm == -1) \/\/ mmm\u306f\u6700\u4f4e\u3067\u3082m=0\u3067-1\u3055\u308c-1\u307e\u3067\r\n            {\r\n                yyy = y - 1;\r\n                mmm = 11;\r\n            }\r\n            textBox5.Text = yyy.ToString() + \"\u5e74\" + mmm.ToString() + \"\u30f6\u6708\";\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>\u30fb\u5f53\u5e74\u5ea6\u672b\u306e\u52e4\u7d9a\u5e74\u6570\/\u5e74\u9f62<\/p>\n<p>\u6642\u3005\u51fa\u3066\u304f\u308b\u5f53\u5e74\u5ea6\u3068\u3044\u3046\u306e\u306f\u3060\u3044\u305f\u30444\u6708\uff5e3\u6708\u306e\u671f\u9593\u3067\u3001\u4f1a\u793e\u306b\u3088\u3063\u3066\u7de0\u65e5\u304c\u6708\u672b\u3067\u306f\u306a\u3044\u5834\u5408\u3082\u3042\u308a\u3001\u4f8b\u3048\u307020\u65e5\u7de0\u306e\u5834\u5408\u306a\u30693\/21\uff5e3\/20\u306e\u3088\u3046\u306b\u306a\u3063\u305f\u308a\u3059\u308b\u3002\u5148\u305a\u3001\u73fe\u5728\u306e\u5e74\u306e3\u670820\u65e5\u3068\u3057\u3066\u3001\u3082\u3057\u73fe\u5728\u304c3\u670820\u65e5\u4ee5\u964d\u306e\u5834\u5408\u3001\u73fe\u5728\u306e\u5e74\u306b+1\u5e74\u306e3\u670820\u65e5\u306b\u3059\u308b\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u5e74\u5ea6\u672b\u304c12\/31\u3092\u6307\u3059\u5834\u5408\u306f\u3001\u73fe\u5728\u306e\u5e74\u306e12\u670831\u65e5\u3068\u3059\u308c\u3070\u3044\u3044\u306e\u3067\u7279\u306b\u8a08\u7b97\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u3002<\/p>\n<pre class=\"lang:c# decode:true \">using System;\r\nusing System.Windows.Forms;\r\n\r\nnamespace WindowsFormsApp1\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n            textBox1.LostFocus += DateParse;\r\n            textBox2.LostFocus += DateParse;\r\n        }\r\n\r\n        private void DateParse(object sender, EventArgs e)\r\n        {\r\n            TextBox textBox = (TextBox)sender;\r\n            try\r\n            {\r\n                textBox.Text = DateTime.Parse(textBox.Text).ToString(\"yyyy\/MM\/dd\");\r\n            }\r\n            catch\r\n            {\r\n                textBox.Text = \"\";\r\n            }\r\n            GetDuration();\r\n        }\r\n\r\n        private DateTime GetYearEnd(DateTime target)\r\n        {\r\n            var yearEnd = new DateTime(target.Year, 3, 20);\r\n            if (target &gt; yearEnd) yearEnd = yearEnd.AddYears(1);\r\n            return yearEnd;\r\n        }\r\n\r\n        private void GetDuration()\r\n        {\r\n            if (textBox1.Text == \"\" || textBox2.Text == \"\") return;\r\n\r\n            var startDate = DateTime.Parse(textBox1.Text);\r\n            var endDate = DateTime.Parse(textBox2.Text);\r\n\r\n            endDate = GetYearEnd(endDate); \/\/ \u5e74\u5ea6\u672b\r\n\r\n            if (startDate &gt; endDate) return;\r\n\r\n            int y = endDate.Year - startDate.Year;\r\n            int m = endDate.Month - startDate.Month;\r\n\r\n            if (startDate.Month &gt; endDate.Month)\r\n            {\r\n                y = y - 1;\r\n                m = 12 + m; \/\/ m\u306f\u30de\u30a4\u30ca\u30b9\u306e\u5024\u304c\u5165\u3063\u3066\u3044\u308b\r\n            }\r\n\r\n            bool isLastDay = false;\r\n            if (endDate.Month != endDate.AddDays(1).Month) isLastDay = true; \/\/ \u6708\u672b\u304b\u3069\u3046\u304b\r\n\r\n            int yyy = y;\r\n            int mmm = m;\r\n\r\n            if (startDate.Day &gt; endDate.Day &amp;&amp; !isLastDay) mmm = m - 1;\r\n\r\n            if (mmm == -1) \/\/ mmm\u306f\u6700\u4f4e\u3067\u3082m=0\u3067-1\u3055\u308c-1\u307e\u3067\r\n            {\r\n                yyy = y - 1;\r\n                mmm = 11;\r\n            }\r\n            textBox3.Text = yyy.ToString() + \"\u5e74\" + mmm.ToString() + \"\u30f6\u6708\";\r\n        }\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30fb\u52e4\u7d9a\u5e74\u6570 \u7279\u306b\u5b9a\u3081\u306e\u306a\u3044\u8a08\u7b97\u306e\u5834\u5408\u3001\u7aef\u6570\u51e6\u7406\u306b\u306f\u88c1\u91cf\u304c\u3042\u308b\u3002 \u5e74\u306e\u671f\u9593\u3092\u6c42\u3081\u308b\u5834\u5408\u3001\u4e00\u822c\u7684\u306b\u306f\u4e00\u5e74\u672a\u6e80\u306e\u7aef\u6570\u3092\u5207\u4e0a\u3052(1\u5e74+1\u65e5\u3067\u30822\u5e74)\u3068\u3059\u308b\u3053\u3068\u304c\u591a\u304f\u3001\u540c\u3058\u3088\u3046\u306b\u6708\u306e\u671f\u9593\u3092\u6c42\u3081\u308b\u5834\u5408\u306f\u30011\u30f6\u6708\u672a\u6e80\u306e\u65e5\u306e\u7aef\u6570\u3082\u5207\u4e0a\u3052 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=5142\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# \u52e4\u7d9a\u5e74\u6570\/\u5e74\u9f62 \u4f55\u5e74\u4f55\u30f6\u6708\u306e\u8003\u3048\u65b9&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9,153],"class_list":["post-5142","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net","tag-153"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5142"}],"version-history":[{"count":13,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5142\/revisions"}],"predecessor-version":[{"id":5163,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5142\/revisions\/5163"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}