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
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.