我尝试获取今天的日期 + 时间(00:00:00)
所以我是这样做的:
const startDate = DateTime.fromISO(params.start)
.startOf('day')
.toFormat('yyyy-LL-dd HH:mm:ss');
但是如果我执行console.log()
:
console.log('startData', startDate);
我收到一个错误:
<块引用>line-chart.service.ts:22 startData Invalid DateTime
那么我必须改变什么?
所以我想在这里使用它:
return this.sensorNodeService.cameraDataInInterval(
16,
startDate,
'2021-01-20 23:59:59',
'1'
);
答案 0 :(得分:3)
let c = new Date(); // take the current time
c.setHours(0);
c.setMinutes(0);
c.setSeconds(0);
// prints the current day at 00:00:00 in your timezone
// in the format 2020-12-02 12:10:12
console.log(c.toISOString().replace(/T/, ' ').replace(/\..+/, ''));
编辑:为了以正确的方式格式化代码,我使用了这个问题 here 中的答案。
答案 1 :(得分:0)
以下是日期/时间的方法;或时间! :)
function DateTime() {
return (new Date().toLocaleString("en-US", {year: 'numeric',month: 'numeric',day: 'numeric',hour: "numeric",minute: "numeric",second: "numeric",hour12: true}));
}
console.log(DateTime());
function Time() {
return (new Date().toLocaleString("en-US", {
hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: true
}));
}
console.log(Time());
答案 2 :(得分:0)
var todaydate = new Date();
var datetime = todaydate.getDate() + "/" +
(todaydate.getMonth() + 1) + "/" +
todaydate.getFullYear() + " " +
+todaydate.getHours() + ":" +
todaydate.getMinutes() + ":" +
todaydate.getSeconds();
console.log(datetime);