Wednesday, April 6, 2011

jquery function to convert datetime, split date time "2010-10-18 10:06" to return "18/10/2010" and "10:06"

Hi I was wondering if there is any jquery function around which can take this dateTime "2010-10-18 10:06" and convert and split it returning "2010/10/18" and "10:06".

It would be also nice if the same function could either receive "2010-10-18 10:06" or "2010-10-18" only and return as mentioned above, or different formats besides "2010/10/18" like 18-10-2010" or and 18th of October 2010, giving the option but not that important, just curious about jQuery power dealing with dates.

Thanks.

From stackoverflow
  • datejs. Check it, its cool and it does pretty good job for all the possibilities and error handling is also pretty good.

  • Converting with DateJs should be as easy as:

    var d1 = Date.parse('2010-10-18, 10:06 AM');
    alert(d1.toString('dd/mm/yyyy HH:mm:ss GMT'));
    

    It's currently the best library around

    Cesar Lopez : it says invalid procedure :-(, i copied your example
    Cesar Lopez : Sorry I did not downloaded the datejs.
  • take a look here

    http://github.com/vitch/jquery-methods/raw/master/date.js

    includes a function called fromString which would help you.

0 comments:

Post a Comment