Home >Web Front-end >JS Tutorial >A small example of zero padding in js date and time_javascript skills

A small example of zero padding in js date and time_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:40:551292browse

Copy code The code is as follows:

function getNowFormatDate()
                                                  day = new Date();
var Year = 0;
var Month = 0;
var Day = 0;
var CurrentDate = "";
var CurrentDate = "";
var Month = 0; 🎜> //Year = day.getYear();//There is a bug that displays 108 in 2008 under Firefox
Year = day.getFullYear();//It can be used under Firefox
Month = day.getMonth() 1 ;
Day = day.getDate();
CurrentDate = Year "-";
if (Month >= 10 )
Current Date = Month "-";
}
else
{
CurrentDate = "0" Month "-";
}
if (Day >= 10 )
{
CurrentDate = Day ;
                                                                                                                                                                                                                                                                                        >         }

 
//obtained The time will be filled with zeros
var nowdate = getNowFormatDate();



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn