This time I will show you how to use js to get the current time, and what are theprecautions for using js to get the current time. The following is a practical case, let's take a look.
Date objectsetDate(): Set a certain day of the month.
getFullYear(): Returns a four-digit number representing the year.
getMonth(): Represents the month field, using local time. An integer between 0-11.
getDate(): Get the day of the month.
function GetDateStr(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期 var y = dd.getFullYear(); var ddM = dd.getMonth(); if(ddM.toString().length==1){ var m = dd.getMonth()+1; m = '0'+m;//格式 == 02 }else{ var m = dd.getMonth()+1;//格式 == 10 } var d = dd.getDate(); return y+"-"+m+"-"+d; }
Otherrelated articles!
Recommended reading:Use JS to perform encryption and decryption operations
##How to make a node.js interfaceThe above is the detailed content of How to get the current time using js. For more information, please follow other related articles on the PHP Chinese website!