javascript - Unabe to parse date of different culture -
i want parse date
var newdatetime = new date(date.parse($("#selctedcalendarday").val()));
$("#selctedcalendarday").val()
value 14-okt-2014 in string.
when date 14-oct-2014 parses correctly.
so how can parse date 14-okt-2014?
i'm not sure language using (dutch?) i'll utilize english, it's easy substitute whatever language like. can parse date string 14-oct-2014 using:
function parsedmmmy(s) { // split on . - or / characters var b = s.split(/[-.\/]/); // months in english, alter whatever language suits var months = {jan:0, feb:1, mar:2, apr:3, may:4, jun:5, jul:6, aug:7, sep:8, oct:9, nov:10, dec:11}; // create date object homecoming new date(b[2], months[b[1].tolowercase()], b[0]); } console.log(parsedmmmy('14-oct-2014')); // tue oct 14 2014 00:00:00
note above create local date object. doesn't validation of values if give string 31-jun-2014 you'll date object 01-jul-2014. it's easy add together validation (it takes 1 more line of code), may not required if know valid strings passed function.
javascript jquery
No comments:
Post a Comment