Am looking to get the current Datetime, and extract Hours, Minutes, etc., for adding a timestamp to messages..
Why does the console log TypeError: Date.datetimeNow is undefined
for this:
var datetimeNow = Date.now();
var hourNow = datetimeNow.getHours();
var minuteNow = datetimeNow.getMinutes();
Instead of:
var datetimeNow = Date.now();
try this:
var datetimeNow = new Date();
var datetimeNow = new Date();
var hourNow = datetimeNow.getHours();
var minuteNow = datetimeNow.getMinutes();
You need to init datetimeNow
as date object
Date.now()
returns a number representing the number of milliseconds since the UNIX epoch (1970/1/1 00:00:00.000 UTC). Numbers don't have Date methods.
To use Date methods, you need to initialize datetimeNow
as a Date
object.
var datetimeNow = new Date();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With