{"id":5434,"date":"2020-05-25T09:56:29","date_gmt":"2020-05-25T00:56:29","guid":{"rendered":"https:\/\/yumishin.com\/?p=5434"},"modified":"2020-05-25T09:56:29","modified_gmt":"2020-05-25T00:56:29","slug":"rruby-time-date","status":"publish","type":"post","link":"https:\/\/yumishin.com\/?p=5434","title":{"rendered":"Ruby\u306eTime\u30af\u30e9\u30b9\u3068Date\u30af\u30e9\u30b9\u306e\u7279\u5fb4\u3068\u30dd\u30a4\u30f3\u30c8"},"content":{"rendered":"<p>\u3069\u3046\u3082\u3001Ruby\u3092\u3084\u3063\u3066\u3044\u308b\u3082\u306e\u3067\u3059\u3002\u7a81\u7136\u3067\u3059\u304cTime\u30af\u30e9\u30b9\u3068Date\u30af\u30e9\u30b9\u3063\u3066\u3088\u304f\u5206\u304b\u3089\u306a\u304f\u3042\u308a\u307e\u305b\u3093\u304b\uff1f\u4eca\u56de\u306f\u305d\u3093\u306a\u4eba\u306e\u305f\u3081\u306b\u3056\u3063\u304f\u308a\u3068\u6982\u8981\u3092\u307e\u3068\u3081\u3066\u304a\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-0\">Time\u30af\u30e9\u30b9\u3068Date\u30af\u30e9\u30b9<\/h2>\n<p>\u3056\u3063\u304f\u308a\u3068\u3057\u305f\u9055\u3044\u3067\u3059\u304c\u3001Time\u30af\u30e9\u30b9\u306f\u6642\u523b\u3092\u8868\u73fe\u3059\u308b\u305f\u3081\u306e\u30af\u30e9\u30b9\u3067\u3001Date\u30af\u30e9\u30b9\u306f\u5e74\u6708\u65e5\u3060\u3051\u3092\u6271\u3046\u30af\u30e9\u30b9\u3067\u3059\u3002<\/p>\n<h3 id=\"i-1\">Time\u30af\u30e9\u30b9<\/h3>\n<h4 id=\"i-2\">Time\u30af\u30e9\u30b9\u3067\u6642\u523b\u3092\u53d6\u5f97\u3059\u308b<\/h4>\n<p>Time.new\u304bTime.now\u3067\u73fe\u5728\u306e\u6642\u523b\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4 id=\"i-3\">Time\u30af\u30e9\u30b9\u3067\u306e\u6642\u523b\u8a08\u7b97<\/h4>\n<p>Time\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540c\u58eb\u3092\u6bd4\u8f03\u3057\u305f\u308a\u3001\u8a08\u7b97\u3057\u3066\u5dee\u3092\u6c42\u3081\u305f\u308a\u3067\u304d\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u51fa\u529b\u7d50\u679c\u306f\u5e38\u306b\u79d2\u3067\u63db\u7b97\u3055\u308c\u308b\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> Ruby<\/span><\/p>\n<pre><code>t = Time.now\nt2 = t + 60 * 60 * 24&nbsp; #=&gt;t2\u306724\u6642\u9593\u5f8c\u306e\u6642\u523b\u3092\u8868\u793a\u3059\u308b<\/code><\/pre>\n<\/div>\n<h3 id=\"i-4\">Date\u30af\u30e9\u30b9<\/h3>\n<h4 id=\"i-5\">Date\u30af\u30e9\u30b9\u3067\u65e5\u4ed8\u3092\u53d6\u5f97\u3059\u308b<\/h4>\n<p>\u6700\u521d\u306brequire \u201cdate\u201d\u3057\u3066\u304b\u3089\u3001Date.today\u3067\u4eca\u65e5\u306e\u65e5\u4ed8\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4 id=\"i-6\">Date\u30af\u30e9\u30b9\u3067\u306e\u65e5\u4ed8\u8a08\u7b97<\/h4>\n<p>Date\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3082\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540c\u58eb\u3067\u5dee\u3092\u6c42\u3081\u305f\u308a\u3001\u6bd4\u8f03\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u51fa\u529b\u7d50\u679c\u306f\u3001\u65e5\u3092\u5358\u4f4d\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>d1 = Date.new(2015, 1, 1)\nd2 = Date.new(2015, 1, 4)\nputs d2 - d1 #=&gt; 3\/1r<\/code><\/pre>\n<\/div>\n<div class=\"memo \">\n<div class=\"memo_ttl dfont\"> MEMO<\/div>\n<p>\u3061\u306a\u307f\u306b\u51fa\u529b\u7d50\u679c\u306fRational\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306a\u308a\u307e\u3059\u3002<\/p><\/div>\n<h3 id=\"i-7\">Time\u3068Date\u306e\u5909\u63db<\/h3>\n<p>to_time\u30e1\u30bd\u30c3\u30c9\u3068to_date\u30e1\u30bd\u30c3\u30c9\u3067\u305d\u308c\u305e\u308c\u3092\u5909\u63db\u53ef\u80fd\u3067\u3059\u3002\u305f\u3060\u3057Date\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306f\u6642\u9593\u306e\u6982\u5ff5\u304c\u306a\u3044\u306e\u3067\u3001Date\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6642\u523b\u306b\u5909\u63db\u3057\u305f\u5834\u5408\u306f\u3001\uff10\u6642\uff10\u5206\uff10\u79d2\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>require \"date\"\n\nt1 = Time.now\nputs t1 #=&gt; 2015-09-25 05:46:15 +0900\n\nd = t1.to_date\nputs d #=&gt; 2015-09-25\n\nt2 = d.to_time\nputs t2 #=&gt; 2015-09-25 00:00:00 +0900\n<\/code><\/pre>\n<\/div>\n<h3 id=\"i-8\">\u6642\u523b\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8<\/h3>\n<p>\u6642\u523b\u3092\u3042\u308b\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u5f93\u3063\u3066\u6587\u5b57\u308c\u308b\u3068\u3057\u3066\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\u306f\u3001t.strftime\u3092\u4f7f\u3044\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u5f15\u6570\u3068\u3057\u3066\u6e21\u305b\u308b\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u5f62\u5f0f\u306f\u305f\u304f\u3055\u3093\u3042\u308b\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b5\u30a4\u30c8\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3088\u304f\u4f7f\u3046\u306e\u306f\uff05Y\u3001%d\u3001%m\u306a\u3069\u3067\u3059\u3002<\/p>\n<p>  <a class=\"reference table\" href=\"https:\/\/docs.ruby-lang.org\/ja\/latest\/method\/Time\/i\/strftime.html\" rel=\"noopener noreferrer\"><br \/>\n    <span class=\"tbcell refttl\">\u53c2\u8003<\/span><br \/>\n    <span class=\"tbcell refcite\">Time#strftime<span>Ruby\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/span><\/span><br \/>\n  <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3046\u3082\u3001Ruby\u3092\u3084\u3063\u3066\u3044\u308b\u3082\u306e\u3067\u3059\u3002\u7a81\u7136\u3067\u3059\u304cTime\u30af\u30e9\u30b9\u3068Date\u30af\u30e9\u30b9\u3063\u3066\u3088\u304f\u5206\u304b\u3089\u306a\u304f\u3042\u308a\u307e\u305b\u3093\u304b\uff1f\u4eca\u56de\u306f\u305d\u3093\u306a\u4eba\u306e\u305f\u3081\u306b\u3056\u3063\u304f\u308a\u3068\u6982\u8981\u3092\u307e\u3068\u3081\u3066\u304a\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 Time\u30af\u30e9\u30b9\u3068Date\u30af\u30e9\u30b9 \u3056\u3063\u304f\u308a\u3068 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":5440,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[272],"tags":[],"class_list":{"0":"post-5434","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-programing","8":"entry"},"_links":{"self":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5434"}],"version-history":[{"count":3,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5434\/revisions"}],"predecessor-version":[{"id":5439,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5434\/revisions\/5439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/media\/5440"}],"wp:attachment":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}