snipt

Ctrl+h for KB shortcuts

Java

Date to XMLGregorianCalendar

1
2
3
4
GregorianCalendar gregorianCalendar = new GregorianCalendar();
Date date = new Date();
gregorianCalendar.setTime(date);
XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
https://snipt.net/embed/31c7f51c792da0ab15b0e65d68c2b262/
/raw/31c7f51c792da0ab15b0e65d68c2b262/
31c7f51c792da0ab15b0e65d68c2b262
java
Java
4
2019-06-21T23:10:15
True
False
False
Nov 15, 2013 at 12:50 AM
/api/public/snipt/94290/
date-to-xmlgregoriancalendar
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">GregorianCalendar</span> <span class="n">gregorianCalendar</span> <span class="o">=</span> <span class="k">new</span> <span class="n">GregorianCalendar</span><span class="o">();</span> </span><span id="L-2"><a name="L-2"></a><span class="n">Date</span> <span class="n">date</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Date</span><span class="o">();</span> </span><span id="L-3"><a name="L-3"></a><span class="n">gregorianCalendar</span><span class="o">.</span><span class="na">setTime</span><span class="o">(</span><span class="n">date</span><span class="o">);</span> </span><span id="L-4"><a name="L-4"></a><span class="n">XMLGregorianCalendar</span> <span class="n">xmlGregorianCalendar</span> <span class="o">=</span> <span class="n">DatatypeFactory</span><span class="o">.</span><span class="na">newInstance</span><span class="o">().</span><span class="na">newXMLGregorianCalendar</span><span class="o">(</span><span class="n">gregorianCalendar</span><span class="o">);</span> </span></pre></div> </td></tr></table>
"gregorian calendar", "xml gregorian calendar", date, java

Java

Java :: Loading and using a properties file

1
2
3
4
5
6
7
8
Properties misPropiedades = new Properties();

File miFichero = new File( "xxx.properties" );   
misPropiedades.load( new FileInputStream( miFichero.getCanonicalPath() ) );

String miPropertyXXX = misPropiedades.getProperty( "propertyXXX" );
String miPropertyYYY = misPropiedades.getProperty( "propertyYYY" );
String miPropertyZZZ = misPropiedades.getProperty( "propertyZZZ" );
https://snipt.net/embed/0e929c42cb3d307d85bb7ec3ed52bf52/
/raw/0e929c42cb3d307d85bb7ec3ed52bf52/
0e929c42cb3d307d85bb7ec3ed52bf52
java
Java
8
2019-06-23T19:31:42
True
False
False
/api/public/snipt/88450/
java-load-a-properties-file
<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> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">Properties</span> <span class="n">misPropiedades</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Properties</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">File</span> <span class="n">miFichero</span> <span class="o">=</span> <span class="k">new</span> <span class="n">File</span><span class="o">(</span> <span class="s">&quot;xxx.properties&quot;</span> <span class="o">);</span> </span><span id="L-4"><a name="L-4"></a><span class="n">misPropiedades</span><span class="o">.</span><span class="na">load</span><span class="o">(</span> <span class="k">new</span> <span class="n">FileInputStream</span><span class="o">(</span> <span class="n">miFichero</span><span class="o">.</span><span class="na">getCanonicalPath</span><span class="o">()</span> <span class="o">)</span> <span class="o">);</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="n">String</span> <span class="n">miPropertyXXX</span> <span class="o">=</span> <span class="n">misPropiedades</span><span class="o">.</span><span class="na">getProperty</span><span class="o">(</span> <span class="s">&quot;propertyXXX&quot;</span> <span class="o">);</span> </span><span id="L-7"><a name="L-7"></a><span class="n">String</span> <span class="n">miPropertyYYY</span> <span class="o">=</span> <span class="n">misPropiedades</span><span class="o">.</span><span class="na">getProperty</span><span class="o">(</span> <span class="s">&quot;propertyYYY&quot;</span> <span class="o">);</span> </span><span id="L-8"><a name="L-8"></a><span class="n">String</span> <span class="n">miPropertyZZZ</span> <span class="o">=</span> <span class="n">misPropiedades</span><span class="o">.</span><span class="na">getProperty</span><span class="o">(</span> <span class="s">&quot;propertyZZZ&quot;</span> <span class="o">);</span> </span></pre></div> </td></tr></table>
java