{"id":7073,"date":"2019-11-17T18:47:22","date_gmt":"2019-11-17T09:47:22","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=7073"},"modified":"2023-05-27T22:34:06","modified_gmt":"2023-05-27T13:34:06","slug":"%e3%80%90ruby%e3%80%91%e6%97%a5%e4%bb%98%e3%82%84%e6%99%82%e5%88%bb%e3%82%92%e6%89%b1%e3%81%86%e3%82%af%e3%83%a9%e3%82%b9","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=7073","title":{"rendered":"\u3010Ruby\u3011\u65e5\u4ed8\u3084\u6642\u523b\u3092\u6271\u3046\u30af\u30e9\u30b9"},"content":{"rendered":"<h2>Time\u30af\u30e9\u30b9<\/h2>\n<ul>\n<li>\u65e5\u4ed8\u3092\u6271\u3046\u30af\u30e9\u30b9\u3067\u7d44\u307f\u8fbc\u307f\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\uff08require\u306f\u4e0d\u8981\uff09<\/li>\n<li>\u9ad8\u901f\u306b\u52d5\u4f5c\u3092\u3057\u307e\u3059\u3002<\/li>\n<li>UNIX\u6642\u9593\u306b\u4f9d\u5b58\u3059\u308b\u305f\u30812038\u5e74\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002(Ruby1.9.2\u3067\u5bfe\u5fdc\u306f\u3055\u308c\u307e\u3057\u305f\u3002\uff09<\/li>\n<li>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u304c\u30ed\u30b1\u30fc\u30eb\u306b\u4f9d\u5b58\u3059\u308b\u3002<\/li>\n<\/ul>\n<h3>now\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u73fe\u5728\u65e5\u6642\u3092\u53d6\u5f97\u3059\u308b\u3002<\/p>\n<h4>zone\u30e1\u30bd\u30c3\u30c9<\/h4>\n<p>\u3069\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3067\u304d\u308b\u3002\uff08\u4f8b\uff1aTime.now.zone\uff09<\/p>\n<h3>new\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u4efb\u610f\u306e\u65e5\u6642\u306e\u65e5\u6642\u3092\u751f\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true\">Time.new(yyyy,mm,dd,hh,mm)<\/pre>\n<h3>strftime\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u597d\u304d\u306a\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u65e5\u6642\u3092\u751f\u6210\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">Time.new().strftime('%Y\u5e74 %m\u6708 %d\u65e5')<\/pre>\n<p>%\u3067\u6307\u5b9a\u3067\u304d\u308b\u6587\u5b57\u306b\u306f\u69d8\u3005\u306a\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>Date\u30af\u30e9\u30b9<\/h2>\n<ul>\n<li>\u65e5\u6642\u3092\u6271\u3046\u30af\u30e9\u30b9<\/li>\n<li>\u4f7f\u3046\u5834\u5408\u306frequire\u6587\u304c\u5fc5\u8981\u306b\u306a\u308b\u3002<\/li>\n<li>\u4f5c\u6210\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u81ea\u4f53\u306b\u306f\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u60c5\u5831\u3092\u6301\u3063\u3066\u3044\u306a\u3044\u306e\u3067zone\u30e1\u30bd\u30c3\u30c9\u306f\u306a\u3044\u3002<\/li>\n<\/ul>\n<h3>today\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u4eca\u65e5\u306e\u65e5\u4ed8\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<h3>new\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u4efb\u610f\u306e\u65e5\u4ed8\u3092\u751f\u6210\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true\">Date.new(yyyy,mm,dd)<\/pre>\n<h3>strftime\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u597d\u304d\u306a\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u65e5\u4ed8\u3092\u751f\u6210\u3067\u304d\u307e\u3059\u3002\u4f7f\u3048\u308b%\u306fTime\u30af\u30e9\u30b9\u3068\u307b\u307c\u540c\u7b49\u3067\u3059\u3002<\/p>\n<h2>DateTime\u30af\u30e9\u30b9<\/h2>\n<ul>\n<li>\u65e5\u6642\u3092\u6271\u3046\u30af\u30e9\u30b9<\/li>\n<li>Time\u306b\u6bd4\u3079\u308b\u3068\u9045\u3044\u3002<\/li>\n<li>UNIX\u6642\u9593\u306b\u4f9d\u5b58\u3057\u306a\u3044\u306e\u3067\u3088\u308a\u67d4\u8edf\u306b\u65e5\u6642\u3092\u8868\u73fe\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u304c\u4e16\u754c\u6a19\u6e96\u6642\u306b\u4f9d\u5b58\u3059\u308b\u3002<\/li>\n<\/ul>\n<h2>ActiveSupport::TimeWithZone\u30af\u30e9\u30b9<\/h2>\n<ul>\n<li>Rails\u3067\u65e5\u6642\u3092\u6271\u3046\u5834\u5408\u306b\u63a1\u7528\u3055\u308c\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002<\/li>\n<li>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u4e16\u754c\u6a19\u6e96\u6642\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/li>\n<\/ul>\n<h3>Time.now.zone<\/h3>\n<p>\u73fe\u5728\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3<\/p>\n<h3>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u5909\u3048\u308b\u306b\u306f\uff1f<\/h3>\n<p>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u4e0b\u8a18\u306e\uff12\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3075\u3041\u3044\u308b\u3067\u8d77\u52d5\u6642\u306b\u9069\u5207\u306a\u5024\u306b\u3059\u308b\u65b9\u6cd5<\/h4>\n<p>config\/application.rb\u306b\u4ee5\u4e0b\u306e\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">module \u30a2\u30d7\u30ea\u540d\r\n  class Application &lt; Rails::Application\r\n    # Initialize configuration defaults for originally generated Rails version.\r\n    config.load_defaults 5.2\r\n    config.time_zone = 'Asia\/Tokyo'\u3000\u2605\u8ffd\u52a0\r\n\u3000\u3000\u2025<\/pre>\n<h4>Rails\u30a2\u30d7\u30ea\u306e\u4e2d\u3067\u52d5\u7684\u306b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u5909\u66f4\u3059\u308b\u65b9\u6cd5<\/h4>\n<p>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u65e5\u672c\u306b\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">Time.zone = 'Asia\/Tokyo'<\/pre>\n<h2>Rails\u3067\u65e5\u6642\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u5171\u901a\u5316\u3059\u308b\u306b\u306f\uff1f<\/h2>\n<p>\u4e0b\u8a18\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<h3>config\/initializers\/time_formats.rb<\/h3>\n<p>\u4f8b\u3048\u3070\u3001\u65e5\u672c\u8a9e\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u3042\u308c\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">Time::DATE_FORMATS[:date_jp] = '%Y\u5e74 %m\u6708 %d\u65e5'<\/pre>\n<p>Rails\u306e\u518d\u8d77\u52d5\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002Rails\u306e\u5b9f\u88c5\u306e\u4e2d\u3067\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">Time\u30af\u30e9\u30b9.to_s(:date_jp)<\/pre>\n","protected":false},"excerpt":{"rendered":"Time\u30af\u30e9\u30b9 \u65e5\u4ed8\u3092\u6271\u3046\u30af\u30e9\u30b9\u3067\u7d44\u307f\u8fbc\u307f\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\uff08require\u306f\u4e0d\u8981\uff09 \u9ad8\u901f\u306b\u52d5\u4f5c\u3092\u3057\u307e\u3059\u3002 UNIX\u6642\u9593\u306b\u4f9d\u5b58\u3059\u308b\u305f\u30812038\u5e74\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002(Ruby1.9.2\u3067\u5bfe\u5fdc\u306f\u3055\u308c\u307e\u3057\u305f\u3002\uff09 \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u304c\u30ed\u30b1 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[48,36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7073"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7073"}],"version-history":[{"count":13,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7073\/revisions"}],"predecessor-version":[{"id":20475,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7073\/revisions\/20475"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7073"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}