ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

node-red中输出当前时间

node-red中输出当前时间

在node-red中输出当前时间,并指定时区为北京时间,时间格式为:YYYY-MM-DD HH:mm:ss

可以使用moment.js库,也可以自行写一个function,介绍一下使用自定义function的方法。

var now =new Date();   
var formattedDate = now.toLocaleString("zh-CN", {timeZone: "Asia/Shanghai",hour12: false,year: "numeric",month: "2-digit",day: "2-digit",hour: "2-digit",minute: "2-digit",second: "2-digit",
});
formattedDate = formattedDate.replace(/\//g, "-");
msg.payload=formattedDate;
return msg;

返回列表