getHours and getMinutes issue on Date object

#1

I got a return "TypeError: time.getHours is not a function".

Why getHours is not a function while time is a date object?

var time = new Date().toLocaleTimeString();

flow.set("currenttime", time); //store at "currenttime"

//var hh = new Date(time).getHours();

//var mm = new Date(time).getMinutes();

var hh = time.getHours();

var mm = time.getMinutes();

msg.payload =

{"hour": hh,

"minute": mm,

};

return msg;

0 Likes

#2

As you are declared - time is string , not the Date object.
You should do something like tihs

var time = new Date();
var displaytime = time.toLocaleTimeString();
var hour = time.getHours();

Chers

0 Likes