How to parse arbitrary dates with datejs parseExact
I want to parse a date in this format '11h04 31/05/开发者_Go百科2011' and other arbitrary formats using datejs, I tried:
Date.parseExact("11h04 31/05/2011", "HH'h'mm dd/MM/yyyy")
and
Date.parseExact("11h04 31/05/2011", "HH\hmm dd/MM/yyyy")
without success. Does anyone knows the exact format/specification of parseExact or how to parse this (and others) arbitrary formats?
In java i would do this:
SimpleDateFormat sdf = new SimpleDateFormat("HH'h'mm dd/MM/yyyy");
sdf.parse(date);
P.S.: yeah, I know I can use a regex to split the string and then parse, but I want to know how to parse it with parseExact.
Thanks in advance.
Does anyone knows the exact format/specification of parseExact
Here is a link to the date.js format specifiers used by date.js and parseExact
http://code.google.com/p/datejs/wiki/FormatSpecifiers#CUSTOM_DATE_AND_TIME_FORMAT_SPECIFIERS
I can't find any way to trick the parseExact method into thinking the formatString doesn't contain a literal h between HH and mm. Tried \u0068, \0x68, no luck.
I think your best bet is
var date = "11h04 31/05/2011";
Date.parseExact(date.replace("h",""),"HHmm dd/MM/yyyy")
精彩评论