const fs = require('fs'); let path = './tmp/abc/yy' async function main(){ let a = await fs.promises.mkdir(path,{recursive: true }); console.log(a); } main(); function dateFormat(date = new Date(), format = 'YY-MM-DD H:m:s') { format = format.toLocaleUpperCase(); const config = { YY: date.getFullYear(), MM: ('0' + (date.getMonth() + 1)).substr(-2, 2), //getMonth() 方法根据本地时间返回指定日期的月份(从 0 到 11) DD: ('0' + date.getDate()).substr(-2, 2), H: ('0' + date.getHours()).substr(-2, 2), M: ('0' + date.getMinutes()).substr(-2, 2), S: ('0' + date.getSeconds()).substr(-2, 2), } for (const key in config) { format = format.replace(key, config[key]) } return format } console.log(dateFormat(new Date(),'YYMMDD'))