How do I get the time of day in javascript/Node.js?

后端 未结 9 793
青春惊慌失措
青春惊慌失措 2020-12-23 13:23

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

9条回答
  •  生来不讨喜
    2020-12-23 13:29

    You should checkout the Date object.

    In particular, you can look at the getHours() method for the Date object.

    getHours() return the time from 0 - 23, so make sure to deal with it accordingly. I think 0-23 is a bit more intuitive since military time runs from 0 - 23, but it's up to you.

    With that in mind, the code would be something along the lines of:

    var date = new Date();
    var current_hour = date.getHours();
    

提交回复
热议问题