如何及时获取今天的日期+ 00:00:00

How to get date of today + 00:00:00 in time

我尝试获取今天的日期 + 时间 (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'
    );

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

以下是您如何做到的,两者都适用 date/time;或时间! :)

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());

var todaydate = new Date();
var datetime = todaydate.getDate() + "/" +
  (todaydate.getMonth() + 1) + "/" +
  todaydate.getFullYear() + " " +
  +todaydate.getHours() + ":" +
  todaydate.getMinutes() + ":" +
  todaydate.getSeconds();
  
  
console.log(datetime);