snipt

Ctrl+h for KB shortcuts

Ruby

Convert to local datetime in Ruby (and Rails)

1
2
3
#Assuming a local active record model named Lead...
lead.created_at.strftime("%m/%d/%y %l:%M %p")
#outputs this as 07/07/12  6:04 PM
https://snipt.net/embed/41ff922a9adb08fe295ac63eceb8516f/
/raw/41ff922a9adb08fe295ac63eceb8516f/
41ff922a9adb08fe295ac63eceb8516f
rb
Ruby
3
2019-06-15T18:42:29
True
False
False
Jul 21, 2012 at 10:34 PM
/api/public/snipt/44278/
convert-to-local-datetime-in-ruby-and-rails
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">#Assuming a local active record model named Lead...</span> </span><span id="L-2"><a name="L-2"></a><span class="n">lead</span><span class="o">.</span><span class="n">created_at</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%m/%d/%y %l:%M %p&quot;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="c1">#outputs this as 07/07/12 6:04 PM</span> </span></pre></div> </td></tr></table>
date_format, datetime, rails, ruby