At first, the toLocaleString () method was used for brevity, and the problem arose.
<script type= "Text/javascript" > new Date (parseint (1421683200) *). toLocaleString (); The results under IE Browser are: January 20, 2015 0:00:00 //google Browser results as follows: 2015/1/20 morning 12:00:00 //firefox browser results are: 2015/1/20 12:00:00 The result of the//safari browser is: Tuesday,january 00:00:00</script>
The results of the various browsers are not the same as the wood there? So how do you make the results of each browser the same? In fact, it is very simple, is to obtain the time date, and then get the date, if necessary, you can also get the time and seconds and other required data, and then according to their own needs of the format, the use of the data obtained by themselves stitching a time string can be, so that each browser display is your own definition of the string , of course, there will be no display effect of the situation is not uniform.
<script type= "Text/javascript" > var test = new Date (parseint (1421683200) *); var $_year = Test.getfullyear (); var $_month = parseint (Test.getmonth ()) +1; var $_day = Test.getdate (); var $_f_date = $_year + "-" +$_month+ "-" +$_day alert ($_f_date);//2015-1-20 var $_f_date2 = $_year + "Year" +$_month+ "Month" +$_day+ "Day"; alert ($_f_date2);//January 20, 2015 </script>
Original address: http://www.iyuze.cn/article/574.html
JS converts timestamps into time format strings (compatible with various browsers)