Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update</strong></p> <p>Below you've said:</p> <blockquote> <p>Sorry, i can't predict date format before, it should be like dd-mm-yyyy or dd/mm/yyyy or dd-mmm-yyyy format finally i wanted to convert all this format to dd-MMM-yyyy format. </p> </blockquote> <p>That <strong><em>completely</em></strong> changes the question. It'll be much more complex if you can't control the format. There is nothing built into JavaScript that will let you specify a date format. Officially, the only date format supported by JavaScript is a <a href="http://es5.github.com/#x15.9.1.15" rel="noreferrer">simplified version of ISO-8601</a>: <code>yyyy-mm-dd</code>, although in practice almost all browsers also support <code>yyyy/mm/dd</code> as well. But other than that, you have to write the code yourself or (and this makes much more sense) use a good library. I'd probably use a library like <a href="http://momentjs.com/" rel="noreferrer">moment.js</a> or <a href="http://www.datejs.com/" rel="noreferrer">DateJS</a> (although DateJS hasn't been maintained in years).</p> <hr> <p><strong>Original answer</strong>:</p> <p>If the format is <em>always</em> <code>dd/mm/yyyy</code>, then this is trivial:</p> <pre><code>var parts = str.split("/"); var dt = new Date(parseInt(parts[2], 10), parseInt(parts[1], 10) - 1, parseInt(parts[0], 10)); </code></pre> <p><code>split</code> splits a string on the given delimiter. Then we use <code>parseInt</code> to convert the strings into numbers, and we use the <code>new Date</code> constructor to build a <code>Date</code> from those parts: The third part will be the year, the second part the month, and the first part the day. <code>Date</code> uses zero-based month numbers, and so we have to subtract one from the month number.</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.
 

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