前端:
//vue3
var date = new Date();
let year = date.getFullYear();
var month = date.getMonth() + 1;
var dat = date.getDate();
var hour = date.getHours();
var minutes = date.getMinutes();
var second = date.getSeconds();
当前时间= year + '-' + month + '-' + dat + ' ' + hour + ':' + minutes + ':' + second;
后端:
long l = System.currentTimeMillis(); //获取时间戳效率最高
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = dateFormat.format(l);
System.out.println(format);//2022-09-24 15:12:36