{"id":9714,"date":"2012-04-21T08:00:00","date_gmt":"2012-04-20T23:00:00","guid":{"rendered":"http:\/\/www.sssg.org\/blogs\/hiro345\/?p=9714"},"modified":"2012-04-21T07:18:55","modified_gmt":"2012-04-20T22:18:55","slug":"dart-structured-web-apps-7-date","status":"publish","type":"post","link":"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/9714.html","title":{"rendered":"Dart: Structured web apps [7]  Date"},"content":{"rendered":"<p>Dart\u306eDate\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3068\u73fe\u5728\u6642\u523b\u306a\u3069\u3092\u77e5\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n<!--more--><br \/>\nAPI\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306b\u660e\u8a00\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u304c\u3001Dart\u306eDate\u30af\u30e9\u30b9\u306f\u3001\u300c1970\/01\/01 00:00:00.000\u300d\u3092\u57fa\u6e96\u3068\u3057\u305f\u5b9f\u88c5\u3068\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u73fe\u5728\u6642\u523b\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306enow()\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\uff081), (2\uff09\u3067\u3001\u307e\u305a\u306f\u305d\u308c\u3092\u4f7f\u3063\u3066\u307f\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3060\u3051\u3067\u300ctime :2012-04-21 06:59:47.095\u300d\u306e\u3088\u3046\u306b\u8868\u793a\u3067\u304d\u307e\u3059\u3002current.value\u306f\u3001\u300c1970\/01\/01 00:00:00.000\u300d\u304b\u3089\u7d4c\u904e\u3057\u305f\u30df\u30ea\u79d2\u306e\u5024\u3068\u306a\u308b\u306e\u3067\u300cmsecs:1334959187095\u300d\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u5e74\u6708\u65e5\u306a\u3069\u3092\u500b\u5225\u306b\u53d6\u5f97\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u30b3\u30e1\u30f3\u30c8\u3067\u3001\u5404\u5024\u306e\u3068\u308b\u7bc4\u56f2\u3092\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002weekday\u306fDate\u306b\u5b9a\u6570\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u4f7f\u3063\u3066\u6587\u5b57\u5217\u3078\u5909\u66f4\u3057\u3066\u3044\u307e\u3059\u3002\u6708\u306b\u3064\u3044\u3066\u3082Date\u306b\u5b9a\u6570\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3089\u3092\u4f7f\u3063\u3066\u6587\u5b57\u5217\u3078\u5909\u66f4\u3059\u308b\u3088\u3046\u306b\u3057\u305f\u65b9\u304c\u826f\u3044\u306e\u3067\u3059\u304c\u3001\u3061\u3087\u3063\u3068\u624b\u3092\u629c\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; gutter: true\">\r\nclass DateSample {\r\n  void run() {\r\n    Date current = new Date.now();\r\n    print(&quot;time :${current}&quot;); \/\/ (1)\r\n    print(&quot;msecs:${current.value}&quot;); \/\/ (2)\r\n    \r\n    int y = current.year;\r\n    int m = current.month; \/\/ 1..12\r\n    int d = current.day; \/\/ 1..31\r\n    int h = current.hours; \/\/ 0..23\r\n    int min = current.minutes; \/\/ 0..59\r\n    int s = current.seconds; \/\/ 0..59\r\n    int ms = current.milliseconds; \/\/ 0..999\r\n    int w = current.weekday;\r\n    String weekday = &quot;&quot;;\r\n    switch(w) {\r\n      case Date.MON: weekday = &quot;MON&quot;; break;\r\n      case Date.TUE: weekday = &quot;TUE&quot;; break;\r\n      case Date.WED: weekday = &quot;WED&quot;; break;\r\n      case Date.THU: weekday = &quot;THU&quot;; break;\r\n      case Date.FRI: weekday = &quot;FRI&quot;; break;\r\n      case Date.SUN: weekday = &quot;SUN&quot;; break;\r\n      case Date.SAT: weekday = &quot;SAT&quot;; break;\r\n    }\r\n    print(&quot;${y}\/${m}\/${d} ${h}:${min}:${s}.${ms} (${weekday})&quot;);\r\n    \r\n    Date date = new Date.withTimeZone(1970, 1, 1, 0, 0, 0, 0, new TimeZone.utc());\r\n    print(&quot;date(UTC)          :${date}&quot;);\r\n    print(&quot;date.value(UTC)    :${date.value}&quot;); \/\/ 1970\/01\/01 00:00:00.000\u304c\u57fa\u6e96\r\n    print(&quot;current-date       :${current.difference(date)}&quot;);\r\n    print(&quot;current-date(day)  :${current.difference(date).inDays}&quot;);\r\n    print(&quot;current-date(hours):${current.difference(date).inHours}&quot;);\r\n    print(&quot;current-date(mins) :${current.difference(date).inMinutes}&quot;);\r\n    print(&quot;current-date(secs) :${current.difference(date).inSeconds}&quot;);\r\n    print(&quot;current-date(msecs):${current.difference(date).inMilliseconds}&quot;);\r\n    date = new Date.fromEpoch(0, new TimeZone.local());\r\n    print(&quot;date(Local)        :${date}&quot;);\r\n    print(&quot;date.value(Local)  :${date.value}&quot;);\r\n  }\r\n}\r\nvoid main() {\r\n  DateSample app = new DateSample();\r\n  app.run();\r\n}\r\n<\/pre>\n<p>Date\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bfwithTimeZone()\u3084\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bffromEpoch()\u3092\u4f7f\u3046\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002withTimeZone()\u306f\u3001\u6642\u523b\u3068\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3057\u307e\u3059\u3057\u3001fromEpoch()\u306f1970\/01\/01 00:00:00.000\u304b\u3089\u306e\u7d4c\u904e\u30df\u30ea\u79d2\u6570\u3068\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3067\u306f1970\/01\/01 00:00:00.000\u306b\u76f8\u5f53\u3059\u308bDate\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u304c\u3001withTimeZone()\u3067\u306fUTC\u3092\u3001fromEpoch()\u3067\u306f\u30ed\u30fc\u30ab\u30eb\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u9055\u3044\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u305f\u3081\u3001date.value\u306e\u8868\u793a\u3067UTC\u306e\u3082\u306e\u306f\u300c1970-01-01 00:00:00.000Z\u300d\u3068\u306a\u308a\u307e\u3059\u304c\u3001\u30ed\u30fc\u30ab\u30eb\u306e\u3082\u306e\u306f\u300c1970-01-01 09:00:00.000\u300d\u3068\u306a\u308a\u307e\u3059\u3002inMilliseconds()\u306e\u3088\u3046\u306a\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3068\u30011970\/01\/01 00:00:00.000\u304b\u3089\u306e\u7d4c\u904e\u6642\u9593\u3092\u77e5\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\ntime :2012-04-21 06:59:47.095\r\nmsecs:1334959187095\r\n2012\/4\/21 6:59:47.95 (SAT)\r\ndate(UTC)          :1970-01-01 00:00:00.000Z\r\ndate.value(UTC)    :0\r\ncurrent-date       :370821:59:47.095\r\ncurrent-date(day)  :15450\r\ncurrent-date(hours):370821\r\ncurrent-date(mins) :22249319\r\ncurrent-date(secs) :1334959187\r\ncurrent-date(msecs):1334959187095\r\ndate(Local)        :1970-01-01 09:00:00.000\r\ndate.value(Local)  :0\r\n<\/pre>\n<ul>\n<li>\u30af\u30e9\u30b9\u30d9\u30fc\u30b9\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u57fa\u790e\u3092\u5b66\u3076\u306b\u306f &#8230; <a type=\"amzn\" asin=\"484432523X\">\u6539\u8a02\u7248 \u57fa\u790eJava(CD-ROM\u4ed8) (IMPRESS KISO SERIES)<\/a><\/li>\n<li>\u30af\u30e9\u30b9\u30d9\u30fc\u30b9\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3092\u5b66\u3076\u306b\u306f &#8230; <a type=\"amzn\" asin=\"4894717166\">\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9eJava (The Java Series)<\/a><\/li>\n<li>\u95a2\u6570\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3092\u5b66\u3076\u306b\u306f &#8230; <a type=\"amzn\" asin=\"4844330845\">Scala\u30b9\u30b1\u30fc\u30e9\u30d6\u30eb\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7b2c2\u7248<\/a><\/li>\n<li>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u7406\u8ad6\u3092\u5b66\u306b\u306f &#8230; <a type=\"amzn\" asin=\"4781912850\">\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u57fa\u790e\u6982\u5ff5 (\u30e9\u30a4\u30d6\u30e9\u30ea\u60c5\u5831\u5b66\u30b3\u30a2\u30fb\u30c6\u30ad\u30b9\u30c8) <\/a><\/li>\n<\/ul>\n<p><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=484432523X&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=4894717166&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=4844330845&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=4781912850&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dart\u306eDate\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3068\u73fe\u5728\u6642\u523b\u306a\u3069\u3092\u77e5\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[638,684,693],"class_list":["post-9714","post","type-post","status-publish","format-standard","hentry","category-program","tag-dart","tag-dartlang","tag-date"],"_links":{"self":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/9714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/comments?post=9714"}],"version-history":[{"count":6,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/9714\/revisions"}],"predecessor-version":[{"id":9790,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/9714\/revisions\/9790"}],"wp:attachment":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/media?parent=9714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/categories?post=9714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/tags?post=9714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}