nodered获取简单的时间
1.添加simpletime 的节点
2. 添加一个inject节点用来每1s循环获取当点的信息
3.添加一个函数节点对simpletime发来的msg进行解析
var payload=msg;
var dateStr=payload.mydate;
var tempstr=dateStr.split(" ");//用空格拆分字符串
var strobj=Object.assign({},tempstr);
var hzweekday,hzmonth;
var weekday=strobj[0];
var month=strobj[1];
var day=strobj[2];
var year=strobj[3];
switch(weekday){
case "Mon":
hzweekday="星期一";
break;
case "Tue":
hzweekday="星期二";
break;
case "Wed":
hzweekday="星期三";
break;
case "Thu":
hzweekday="星期四";
break;
case "Fri":
hzweekday="星期五";
break;
case "Sat":
hzweekday="星期六";
break;
case "Sun":
hzweekday="星期日";
break;
default:
break;
}
switch(month){
case "Jan":
hzmonth="1月";
break;
case "Feb":
hzmonth="2月";
break;
case "Mar":
hzmonth="3月";
break;
case "Apr":
hzmonth="4月";
break;
case "May":
hzmonth="5月";
break;
case "Jun":
hzmonth="6月";
break;
case "Jul":
hzmonth="7月";
break;
case "Aug":
hzmonth="8月";
break;
case "Sept":
hzmonth="9月";
break;
case "Sep":
hzmonth="9月";
break;
case "Oct":
hzmonth="10月";
break;
case "Nov":
hzmonth="11月";
break;
case "Dec":
hzmonth="12月";
break;
default:
break;
}
msg.payload=year+"年"+hzmonth+day+hzweekday+payload.mytimes;
return msg;
4.添加一个文本进行显示
结果如下;
本文来自博客园,作者:wiselee/,转载请注明原文链接:https://www.cnblogs.com/wiseleer/p/16195882.html