javascript - Globalize.js - how to parse date and time rather than just date -


globalize.js allows parse date string based on current culture applied

var date = globalize.parsedate("17/07/2013"); //wed jul 17 00:00:00 pdt 2013 

what parse datetime. javascript date object handles this, i'm surprised globalize.js library doesn't.

var date = new date("07/17/2013 11:55 pm"); //wed jul 17 23:55:00 pdt 2013 var date = globalize.parsedate("07/17/2013 11:55 pm"); //null 

am missing something? i'm leaning towards parsing time portion myself. there library extends globalize.js provides kind of functionality? i've looked around haven't found much.

update w/ accepted answer

you can parse date if know format date in.

    var date = globalize.parsedate("17/07/2013 11:55 pm", "mm/dd/yyyy hh:mm tt");      //date = null 

in example date null because expects time period in format of a.m or p.m.. once changed able parse datetime.

   var date = globalize.parsedate("17/07/2013 11:55 p.m.", "mm/dd/yyyy hh:mm tt");     //date = wed jul 17 23:55:00 pdt 2013 

note: applicable deprecated globalize 0.x.

note 2: passing hardcoded pattern not i18n recommendation.

if know pattern using:

var date = globalize.parsedate("07/17/2013 11:55 pm", "mm/dd/yyyy hh:mm tt"); 

if don't know pattern:

var date = globalize.parsedate("07/17/2013 11:55 pm", globalize.culture().calendar.patterns.d + " " + globalize.culture().calendar.patterns.t) 

the line above assuming current culture, if need other culture or if haven't established local culture calling globalize.culture("") specify culture on culture().

i ran on scenario few minutes ago, , found solution, latest messy, hope there cleaner way this.

note: applicable deprecated globalize 0.x.

note 2: passing hardcoded pattern not i18n recommendation.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -