Javascript Date from string giving different output from Chrome to Firefox -


i'm trying write javascript code format date want, have troubles making work on firefox (it's working want on chrome).

the input have in form 05/01/13 (mm/dd/yy) , want 2013-05-01 (yyyy/mm/dd).

for that, did :

var formdate = document.getelementbyid("start").value; var mydate = new date(formdate); var startdate = new date();  startdate.setmonth(mydate.getmonth() + 1); startdate.setfullyear(mydate.getfullyear()); var formatteddate = startdate.getfullyear() + "-" + ((startdate.getmonth() <= 10) ? "0" : "") + startdate.getmonth() + "-01"; // day 01  alert(formatteddate); 

you can try on both browsers here : http://jsfiddle.net/j4blh/

on google chrome, code gives me example 2013-05-01 may, on firefox, have 1913-05-01.

i know could've written "20" + startdate.getyear() wondering why results different chrome firefox ? , maybe if have better way of writing code pasted here, please let me know :)

thanks !

from spec:

however, expression date.parse(x.tolocalestring()) not required produce same number value preceding 3 expressions and, in general, value produced date.parse implementation-dependent when given string value not conform date time string format (15.9.1.15) , not produced in implementation tostring or toutcstring method.

when creating date object passing date string constructor, method of parsing same date.parse.

your date format, using 2 digit year, not conforming standard. such, seem way these dates parsed implementation specific, meaning depends upon javascript engine being used. in google's case, it's v8, , in firefox, it's tracemonkey or rhino believe.

in short, should use 4 digit years, there no yy in js standard.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -