let log = console.log; function date2Ymd(timestamp=0) { timestamp = timestamp ? (new Date).getTime() + timestamp * 1e3 : undefined; let dateHand = timestamp?new Date(timestamp):new Date(); let month = (dateHand.getMonth() + 1); month = month < 10 ? `0${month}` : month; let date = dateHand.getDate(); date = date < 10 ? `0${date}` : date; return (dateHand.getFullYear() + '-' + (month) + '-' + date) } console.log(date2Ymd()); console.log(date2Ymd(86400))