{"id":144,"date":"2006-07-24T22:36:57","date_gmt":"2006-07-25T03:36:57","guid":{"rendered":"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/07\/24\/ruby-time-formatting\/"},"modified":"2012-06-29T19:40:48","modified_gmt":"2012-06-30T02:40:48","slug":"ruby-time-formatting","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2006\/07\/24\/ruby-time-formatting\/","title":{"rendered":"Ruby Time Formatting"},"content":{"rendered":"<p>The Time class in Ruby has a powerful formatting function which can help you represent the time in a variety of ways.  The strftime function is modeled after C&#8217;s <b>printf<\/b>.  Here are some usages examples:<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\nt = Time.now\r\nt.strftime(&quot;%m\/%d\/%Y %H:%M:%S&quot;) # 07\/24\/2006 09:09:03\r\n\r\nt.strtime(&quot;%A&quot;) # Monday\r\nt.strftime(&quot;%B&quot;) # July\r\n<\/pre>\n<p>You can use the lower case a and b to get the abbreviated name of the weekday and month, respectively.  To get the the day of the year, between 1 &#8211; 366, use the j option.<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\nt.strftime(&quot;%j&quot;) # 205\r\n<\/pre>\n<p>The strftime function is useful when formatting the <b>created_at<\/b> datetime of your Rails application ActiveRecord models.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Time class in Ruby has a powerful formatting function which can help you represent the time in a variety of ways. The strftime function is modeled after C&#8217;s printf. Here are some usages examples: t = Time.now t.strftime(&quot;%m\/%d\/%Y %H:%M:%S&quot;) # 07\/24\/2006 09:09:03 t.strtime(&quot;%A&quot;) # Monday t.strftime(&quot;%B&quot;) # July You can use the lower case [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[22,3],"tags":[743,806,741,744,742],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-2k","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/144"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":2,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":1631,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions\/1631"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}