var RightNow = new Date();
var RightY = RightNow.getFullYear();//年
var RightM = RightNow.getMonth()+1; //月-月份就會從 0 開始, 所以正確月份需加 1
RightM += ''; //轉成字串
//若月份長度為1,則前面補0
if (RightM.length == 1){
RightM = '0'+RightM;
}
var RightD = RightNow.getDate(); //日
RightD += ''; //轉成字串
//若日長度為1,則前面補0
if (RightD.length == 1){
RightD = '0'+RightD;
}
alert(RightY+'-'+RightM+'-'+RightD);
=>YYYY-MM-DD
沒有留言:
張貼留言