{"id":1414,"date":"2021-04-21T00:55:29","date_gmt":"2021-04-20T15:55:29","guid":{"rendered":"http:\/\/leenux.kr\/?p=1414"},"modified":"2021-04-21T01:56:25","modified_gmt":"2021-04-20T16:56:25","slug":"dart-%ec%83%9d%eb%85%84%ec%9b%94%ec%9d%bc-to-%eb%82%98%ec%9d%b4%eb%a7%8c","status":"publish","type":"post","link":"https:\/\/leenux.kr\/?p=1414","title":{"rendered":"[Dart] \uc0dd\ub144\uc6d4\uc77c to \ub098\uc774(\ub9cc)"},"content":{"rendered":"\n<p class=\"has-text-color has-medium-font-size has-very-dark-gray-color\"><strong>String input \uac12 : &#8220;20030603&#8221;<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p class=\"has-text-color has-medium-font-size has-very-dark-gray-color\"><strong>Solution #1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int age(String input){\n  DateTime _dateTime = DateTime(\n      int.parse(input.substring(0, 4)),\n      int.parse(input.substring(5, 6)),\n      int.parse(input.substring(7, 8)),\n  );\n  return DateTime.fromMillisecondsSinceEpoch(\n            DateTime.now().difference(_dateTime).inMilliseconds).year - 1970;\n}\n\nvoid main() {\n  var input = \"20030603\";\n  print(\"\ub300\ud55c\ubbfc\uad6d \ub098\uc774(\ub9cc) : \" + age(input).toString());\n}<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft\"><img loading=\"lazy\" width=\"185\" height=\"33\" src=\"https:\/\/leenux.kro.kr\/wp-content\/uploads\/2021\/04\/image-3.png\" alt=\"\" class=\"wp-image-1415\"\/><figcaption><strong>\uc2e4\ud589 \uacb0\uacfc<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p class=\"has-text-color has-medium-font-size has-very-dark-gray-color\"><strong>Solution #2<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int isAdult(String enteredAge) {\n    var birthDate = DateTime.parse(enteredAge);\n    print(\"set state: $birthDate\");\n    var today = DateTime.now();\n\n    final difference = today.difference(birthDate).inDays;\n    print(difference);\n    final year = difference \/ 365;\n    print(year);\n    return year.toInt();\n }<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft\"><img loading=\"lazy\" width=\"185\" height=\"33\" src=\"https:\/\/leenux.kro.kr\/wp-content\/uploads\/2021\/04\/image-3.png\" alt=\"\" class=\"wp-image-1415\"\/><figcaption><strong>\uc2e4\ud589 \uacb0\uacfc<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Dart] \uc0dd\ub144\uc6d4\uc77c to \ub098\uc774(\ub9cc) \uacf5\uc2dd \ubc0f \ubc29\ubc95 (\uc608\uc81c)<\/p>\n","protected":false},"author":1,"featured_media":1049,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts\/1414"}],"collection":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1414"}],"version-history":[{"count":2,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts\/1414\/revisions"}],"predecessor-version":[{"id":1418,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts\/1414\/revisions\/1418"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/media\/1049"}],"wp:attachment":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}