You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>To get the current date or date-time you can use <code><ahref="https://lubridate.tidyverse.org/reference/now.html">today()</a></code> or <code><ahref="https://lubridate.tidyverse.org/reference/now.html">now()</a></code>:</p>
493
493
<divclass="cell">
494
494
<divclass="sourceCode" id="cb2"><preclass="downlit sourceCode r code-with-copy"><codeclass="sourceCode R"><span><spanclass="fu"><ahref="https://lubridate.tidyverse.org/reference/now.html">today</a></span><spanclass="op">(</span><spanclass="op">)</span></span>
<span><spanclass="co">#> [1] "2024-11-04 10:54:58 PST"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
497
+
<span><spanclass="co">#> [1] "2024-11-10 20:54:07 -03"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
498
498
</div>
499
499
<p>Otherwise, the following sections describe the four ways you’re likely to create a date/time:</p>
<p>You may want to switch between a date-time and a date. That’s the job of <code><ahref="https://lubridate.tidyverse.org/reference/as_date.html">as_datetime()</a></code> and <code><ahref="https://lubridate.tidyverse.org/reference/as_date.html">as_date()</a></code>:</p>
783
783
<divclass="cell">
784
784
<divclass="sourceCode" id="cb13"><preclass="downlit sourceCode r code-with-copy"><codeclass="sourceCode R"><span><spanclass="fu"><ahref="https://lubridate.tidyverse.org/reference/as_date.html">as_datetime</a></span><spanclass="op">(</span><spanclass="fu"><ahref="https://lubridate.tidyverse.org/reference/now.html">today</a></span><spanclass="op">(</span><spanclass="op">)</span><spanclass="op">)</span></span>
<span><spanclass="co">#> [1] "2024-11-04"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
787
+
<span><spanclass="co">#> [1] "2024-11-10"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
788
788
</div>
789
789
<p>Sometimes you’ll get date/times as numeric offsets from the “Unix Epoch”, 1970-01-01. If the offset is in seconds, use <code><ahref="https://lubridate.tidyverse.org/reference/as_date.html">as_datetime()</a></code>; if it’s in days, use <code><ahref="https://lubridate.tidyverse.org/reference/as_date.html">as_date()</a></code>.</p>
<divclass="sourceCode" id="cb28"><preclass="downlit sourceCode r code-with-copy"><codeclass="sourceCode R"><span><spanclass="co"># How old is Hadley?</span></span>
<span><spanclass="co">#> Time difference of 16458 days</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
1013
+
<span><spanclass="co">#> Time difference of 16464 days</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
1014
1014
</div>
1015
1015
<p>A <code>difftime</code> class object records a time span of seconds, minutes, hours, days, or weeks. This ambiguity can make difftimes a little painful to work with, so lubridate provides an alternative which always uses seconds: the <strong>duration</strong>.</p>
1016
1016
<divclass="cell">
1017
1017
<divclass="sourceCode" id="cb29"><preclass="downlit sourceCode r code-with-copy"><codeclass="sourceCode R"><span><spanclass="fu"><ahref="https://lubridate.tidyverse.org/reference/as.duration.html">as.duration</a></span><spanclass="op">(</span><spanclass="va">h_age</span><spanclass="op">)</span></span>
1018
-
<span><spanclass="co">#> [1] "1421971200s (~45.06 years)"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
1018
+
<span><spanclass="co">#> [1] "1422489600s (~45.08 years)"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
1019
1019
</div>
1020
1020
<p>Durations come with a bunch of convenient constructors:</p>
<p>You can find out what R thinks your current time zone is with <code><ahref="https://rdrr.io/r/base/timezones.html">Sys.timezone()</a></code>:</p>
1172
1172
<divclass="cell">
1173
1173
<divclass="sourceCode" id="cb44"><preclass="downlit sourceCode r code-with-copy"><codeclass="sourceCode R"><span><spanclass="fu"><ahref="https://rdrr.io/r/base/timezones.html">Sys.timezone</a></span><spanclass="op">(</span><spanclass="op">)</span></span>
1174
-
<span><spanclass="co">#> [1] "America/Los_Angeles"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
1174
+
<span><spanclass="co">#> [1] "America/Sao_Paulo"</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
1175
1175
</div>
1176
1176
<p>(If R doesn’t know, you’ll get an <code>NA</code>.)</p>
1177
1177
<p>And see the complete list of all time zone names with <code><ahref="https://rdrr.io/r/base/timezones.html">OlsonNames()</a></code>:</p>
<span><spanclass="co">#> # ℹ more rows</span></span></code><buttontitle="Copiar para a área de transferência" class="code-copy-button"><iclass="bi"></i></button></pre></div>
0 commit comments