P粉7425503772023-08-24 09:11:26
var utc = new Date().toJSON().slice(0,10).replace(/-/g,'/'); document.write(utc);
If you want to reuse a utc
variable (e.g. new Date(utc)
), use the replace
option, as Firefox and Safari do not recognize dashes date.
P粉6183582602023-08-24 00:07:53
Use new Date()
Generate a new Date
object containing the current date and time.
var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; document.write(today);