{"id":165,"date":"2014-01-06T16:12:13","date_gmt":"2014-01-06T07:12:13","guid":{"rendered":"http:\/\/gomocool.net\/gomokulog\/?p=165"},"modified":"2014-09-26T11:06:18","modified_gmt":"2014-09-26T02:06:18","slug":"datetime%e3%81%ae-tryparseexact-%e3%81%a8-parseexact","status":"publish","type":"post","link":"https:\/\/gomokulog.gomocool.net\/?p=165","title":{"rendered":"[C#] DateTime\u306e TryParseExact \u3068 ParseExact"},"content":{"rendered":"<p>\u6587\u5b57\u5217\u3092DateTime\u578b\u3068\u3057\u3066\u89e3\u6790\u3057\u305f\u3044\u3068\u304d\u306b\u3001Parse\u3084TryParse\u3092\u4f7f\u3046\u3002<\/p>\n<p>DateTime\u306eParse\u306f\u512a\u79c0\u306a\u306e\u3067\u3001\u5272\u3068\u306a\u3093\u3067\u3082\u89e3\u6790\u3057\u3066\u304f\u308c\u308b\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u5909\u63db\u3067\u304d\u308b\u3082\u306e\u306f\u4f55\u3067\u3082\u5909\u63db\u3059\u308b\u305f\u3081\u3001\u610f\u56f3\u3057\u306a\u3044\u3082\u306e\u3082\u5909\u63db\u3059\u308b\u3002<br \/>\n\u307e\u305f\u3001\u30aa\u30ea\u30b8\u30ca\u30eb\u8981\u7d20\u306e\u5f37\u3044\u5f62\u5f0f\u3060\u3068\u3001\u305d\u306e\u307e\u307e\u3067\u306f\u4f7f\u3048\u306a\u3044\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001ParseExact\u304bTryParseExact\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<p>\u4e0b\u8a18\u306b2\u664215\u5206\u3092\u3044\u304f\u3064\u304b\u306e\u5f62\u5f0f\u306b\u3057\u3066\u6587\u5b57\u5217\u306b\u683c\u7d0d\u3057\u3001\u89e3\u6790\u3092\u884c\u3046\u30b3\u30fc\u30c9\u3068\u5b9f\u884c\u7d50\u679c\u3092\u4e57\u305b\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true\">static void Main(string[] args)\r\n        {\r\n            String time = \"2:15\";\r\n            String time2 = \"02:15\";\r\n            String time3 = \"2\u664215\u5206\";\r\n            String time4 = \"0215\";\r\n            var dataTime = new DateTime();\r\n            if (DateTime.TryParse(time, out dataTime))\r\n            {\r\n                Console.WriteLine(String.Format(\"\u6642\u523b\u306f\uff1a{0}\", dataTime.ToString(\"yyyy\/MM\/dd HH:mm:ss\")));\r\n            }\r\n            else\r\n            {\r\n                Console.WriteLine(String.Format(\"{0}\u3092\u89e3\u6790\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\", time));\r\n            }\r\n\r\n            if (DateTime.TryParse(time2, out dataTime))\r\n            {\r\n                Console.WriteLine(String.Format(\"\u6642\u523b\u306f\uff1a{0}\", dataTime.ToString(\"yyyy\/MM\/dd HH:mm:ss\")));\r\n            }\r\n            else\r\n            {\r\n                Console.WriteLine(String.Format(\"{0}\u3092\u89e3\u6790\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\", time2));\r\n            }\r\n\r\n            if (DateTime.TryParse(time3, out dataTime))\r\n            {\r\n                Console.WriteLine(String.Format(\"\u6642\u523b\u306f\uff1a{0}\", dataTime.ToString(\"yyyy\/MM\/dd HH:mm:ss\")));\r\n            }\r\n            else\r\n            {\r\n                Console.WriteLine(String.Format(\"{0}\u3092\u89e3\u6790\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\", time3));\r\n            }\r\n\r\n            if (DateTime.TryParse(time4, out dataTime))\r\n            {\r\n                Console.WriteLine(String.Format(\"\u6642\u523b\u306f\uff1a{0}\", dataTime.ToString(\"yyyy\/MM\/dd HH:mm:ss\")));\r\n            }\r\n            else\r\n            {\r\n                Console.WriteLine(String.Format(\"{0}\u3092\u89e3\u6790\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\", time4));\r\n            }\r\n\r\n            if (DateTime.TryParseExact(time4, \"HHmm\", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dataTime))\r\n            {\r\n                Console.WriteLine(String.Format(\"\u6642\u523b\u306f\uff1a{0}\", dataTime.ToString(\"yyyy\/MM\/dd HH:mm:ss\")));\r\n            }\r\n            else\r\n            {\r\n                Console.WriteLine(String.Format(\"{0}\u3092\u89e3\u6790\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\", time4));\r\n            }\r\n            Console.ReadLine();\r\n        }<\/pre>\n<p><a href=\"http:\/\/gomocool.net\/gomokulog\/wp-content\/uploads\/2014\/01\/20140106.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-166\" src=\"http:\/\/gomocool.net\/gomokulog\/wp-content\/uploads\/2014\/01\/20140106.png\" alt=\"20140106\" width=\"275\" height=\"106\" \/><\/a><br \/>\n\u307b\u3068\u3093\u3069\u306f\u554f\u984c\u306a\u3044\u304c0215\u306a\u3069\u3001215\u5e74\u306a\u306e\u304b2\u670815\u65e5\u306a\u306e\u304b\u5224\u65ad\u3067\u304d\u306a\u3044\u3082\u306e\u304c\u3042\u308b\u3002<br \/>\n\u305d\u306e\u5834\u5408\u306b\u3001ParseExtra\u3067\u66f8\u5f0f\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001\u89e3\u6790\u53ef\u80fd\u306b\u306a\u308b\u3002<\/p>\n<p>\u307e\u305f\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u306a\u3069\u3092\u4ed8\u3051\u308b\u969b\u306b\u308f\u304b\u308a\u3084\u3059\u3044\u3088\u3046\u306b\u3001hogefile_0215\u3068\u3064\u3051\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u306e\u306b\u3001hogefile_215\u3068\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u306f\u56f0\u308b\u3068\u3044\u3063\u305f\u5834\u5408\u306b\u5fc5\u305aHH:mm\u5f62\u5f0f\u3092\u5f37\u5236\u3055\u305b\u305f\u3044\u5834\u5408\u306b\u3082\u4f7f\u3048\u308b\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001TryParseExtra\u306e3\u3064\u76ee\u306e\u5f15\u6570\u306f\u30ab\u30eb\u30c1\u30e3\u30fc\u3067\u3001\u3068\u308a\u3042\u3048\u305aCultureInfo.InvariantCulture (System.Globalization) \u3092\u6307\u5b9a\u3059\u308b\u304bNull\u3067\u3082\u73fe\u5728\u306e\u30ab\u30eb\u30c1\u30e3\u30fc\u304c\u4f7f\u7528\u3055\u308c\u308b\u3089\u3057\u3044\u3002<\/p>\n<p>4\u3064\u76ee\u306f\u3001DateTimeStyles\u3067\u89e3\u6790\u3059\u308b\u969b\u306b\u7a7a\u767d\u6587\u5b57\u3092\u3069\u3046\u3059\u308b\u304b\u306a\u3069\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u3088\u3046\u3060\u3002<br \/>\n\u3068\u308a\u3042\u3048\u305aSystem.Globalization.DateTimeStyles.None\u3067\u666e\u901a\u306eParse\u30b3\u30de\u30f3\u30c9\u3068\u540c\u3058\u306b\u306a\u308b\u3002<\/p>\n<p>\u57fa\u672c\u306fParse\u3084TryParse\u3067\u5341\u5206\u3060\u3051\u3069\u3001\u305f\u307e\u306b\u30aa\u30ea\u30b8\u30ca\u30eb\u66f8\u5f0f\u3092\u89e3\u6790\u3059\u308b\u5fc5\u8981\u304c\u6709\u3063\u305f\u308a\u53b3\u5bc6\u6027\u304c\u5fc5\u8981\u3060\u3063\u305f\u308a\u306e\u5834\u5408\u306b\u601d\u3044\u51fa\u3059\u3068\u3044\u3044\u304b\u3082\u3002<\/p>\n<p>&nbsp;<\/p>\n<h4>\u8ffd\u8a18<\/h4>\n<p>\u610f\u5916\u3060\u304c\u300120140925\u3068\u3044\u3063\u305f\u3088\u304f\u4f7f\u308f\u308c\u308byyyyMMdd\u5f62\u5f0f\u306f\u666e\u901a\u306b\u306fParse\u3067\u304d\u306a\u304b\u304b\u3063\u305f\u3002<br \/>\nyyyyMMdd\u5f62\u5f0f\u306e\u5834\u5408\u306f\u4e0b\u8a18\u306e\u901a\u308a\u3002<\/p>\n<p>VB.NET\u3000(*\u3053\u306e\u4f8b\u306fVB.NET\u3060\u3051\u3069\u3001C#\u3082\u307b\u307c\u540c\u3058\u3002)<\/p>\n<pre class=\"lang:vbnet decode:true \">Dim strDate As String = \"20140925\"\r\nDim myDate As DateTime = DateTime.ParseExact(strDate, \"yyyyMMdd\", System.Globalization.CultureInfo.InvariantCulture)\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u5b57\u5217\u3092DateTime\u578b\u3068\u3057\u3066\u89e3\u6790\u3057\u305f\u3044\u3068\u304d\u306b\u3001Parse\u3084TryParse\u3092\u4f7f\u3046\u3002 DateTime\u306eParse\u306f\u512a\u79c0\u306a\u306e\u3067\u3001\u5272\u3068\u306a\u3093\u3067\u3082\u89e3\u6790\u3057\u3066\u304f\u308c\u308b\u3002 \u3057\u304b\u3057\u3001\u5909\u63db\u3067\u304d\u308b\u3082\u306e\u306f\u4f55\u3067\u3082\u5909\u63db\u3059\u308b\u305f\u3081\u3001\u610f\u56f3\u3057\u306a\u3044\u3082\u306e\u3082&hellip;  <a href=\"https:\/\/gomokulog.gomocool.net\/?p=165\" class=\"more-link\">more <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-165","post","type-post","status-publish","format-standard","hentry","category-csharp"],"_links":{"self":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165"}],"version-history":[{"count":5,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":272,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions\/272"}],"wp:attachment":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}