I want to get 1 to 24, 1 being 1am Pacific Time.
How can I get that number in Node.JS?
I want to know what time it is in Pacific time right now.
Use the toUTCString() method to get the current date and time in utc, e.g. new Date(). toUTCString() .
This function will return you the date and time in the following format: YYYY:MM:DD:HH:MM:SS
. It also works in Node.js.
function getDateTime() { var date = new Date(); var hour = date.getHours(); hour = (hour < 10 ? "0" : "") + hour; var min = date.getMinutes(); min = (min < 10 ? "0" : "") + min; var sec = date.getSeconds(); sec = (sec < 10 ? "0" : "") + sec; var year = date.getFullYear(); var month = date.getMonth() + 1; month = (month < 10 ? "0" : "") + month; var day = date.getDate(); day = (day < 10 ? "0" : "") + day; return year + ":" + month + ":" + day + ":" + hour + ":" + min + ":" + sec; }
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