snipt

Ctrl+h for KB shortcuts

Java

timestamp

1
2
3
4
5
6
import java.util.Calendar;

String timestamp() {
  Calendar now = Calendar.getInstance();
  return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
https://snipt.net/embed/d799f1c68f91125301c8ea0c06945eeb/
https://snipt.net/raw/d799f1c68f91125301c8ea0c06945eeb/
d799f1c68f91125301c8ea0c06945eeb
java
Java
6
2016-09-25T19:18:39
True
False
False
Jul 15, 2013 at 01:01 PM
/api/public/snipt/67826/
timestamp-1
<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> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kn">import</span> <span class="nn">java.util.Calendar</span><span class="o">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="n">String</span> <span class="nf">timestamp</span><span class="o">()</span> <span class="o">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">Calendar</span> <span class="n">now</span> <span class="o">=</span> <span class="n">Calendar</span><span class="o">.</span><span class="na">getInstance</span><span class="o">();</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="n">String</span><span class="o">.</span><span class="na">format</span><span class="o">(</span><span class="s">&quot;%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS&quot;</span><span class="o">,</span> <span class="n">now</span><span class="o">);</span> </span><span id="L-6"><a name="L-6"></a><span class="o">}</span> </span></pre></div> </td></tr></table>
calendar, time

JavaScript

js utc convert

  utcDateObj = new Date(dateObj.getTime() + (dateObj.getTimezoneOffset() * 60 * 1000));
https://snipt.net/embed/9667e6c3ce0be425ddc30db2f9b41240/
https://snipt.net/raw/9667e6c3ce0be425ddc30db2f9b41240/
9667e6c3ce0be425ddc30db2f9b41240
js
JavaScript
2
2016-09-26T11:35:13
True
False
False
May 20, 2013 at 01:43 PM
/api/public/snipt/61799/
js-utc-convert
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a> <span class="nx">utcDateObj</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">dateObj</span><span class="p">.</span><span class="nx">getTime</span><span class="p">()</span> <span class="o">+</span> <span class="p">(</span><span class="nx">dateObj</span><span class="p">.</span><span class="nx">getTimezoneOffset</span><span class="p">()</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">));</span> </span></pre></div> </td></tr></table>
js, time
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.