Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <a href="https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#parse-java.lang.CharSequence-java.time.format.DateTimeFormatter-" rel="noreferrer"><code>LocalDateTime#parse()</code></a> (or <a href="https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html#parse-java.lang.CharSequence-java.time.format.DateTimeFormatter-" rel="noreferrer"><code>ZonedDateTime#parse()</code></a> if the string happens to contain a time zone part) to parse a <code>String</code> in a certain pattern into a <code>LocalDateTime</code>.</p> <pre><code>String oldstring = "2011-01-18 00:00:00.0"; LocalDateTime datetime = LocalDateTime.parse(oldstring, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")); </code></pre> <p>Use <a href="https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#format-java.time.format.DateTimeFormatter-" rel="noreferrer"><code>LocalDateTime#format()</code></a> (or <a href="https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html#format-java.time.format.DateTimeFormatter-" rel="noreferrer"><code>ZonedDateTime#format()</code></a>) to format a <code>LocalDateTime</code> into a <code>String</code> in a certain pattern.</p> <pre><code>String newstring = datetime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); System.out.println(newstring); // 2011-01-18 </code></pre> <p><strong>Or</strong>, when you're not on Java 8 yet, use <a href="http://docs.oracle.com/javase/8/docs/api/java/text/DateFormat.html#parse-java.lang.String-" rel="noreferrer"><code>SimpleDateFormat#parse()</code></a> to parse a <code>String</code> in a certain pattern into a <code>Date</code>.</p> <pre><code>String oldstring = "2011-01-18 00:00:00.0"; Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(oldstring); </code></pre> <p>Use <a href="http://docs.oracle.com/javase/8/docs/api/java/text/DateFormat.html#format-java.util.Date-" rel="noreferrer"><code>SimpleDateFormat#format()</code></a> to format a <code>Date</code> into a <code>String</code> in a certain pattern.</p> <pre><code>String newstring = new SimpleDateFormat("yyyy-MM-dd").format(date); System.out.println(newstring); // 2011-01-18 </code></pre> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/4216745/java-string-to-date-conversion/">Java string to date conversion</a></li> </ul> <hr> <p><strong>Update</strong>: as per your failed attempt: the patterns are <strong>case sensitive</strong>. Read the <a href="http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html" rel="noreferrer"><code>java.text.SimpleDateFormat</code> javadoc</a> what the individual parts stands for. So stands for example <code>M</code> for months and <code>m</code> for minutes. Also, years exist of four digits <code>yyyy</code>, not five <code>yyyyy</code>. Look closer at the code snippets I posted here above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload