How does js get the timestamp from the beginning of a certain month of a year?

how does js get the timestamp of the beginning of a certain month in a certain year? Php can be realized by mktime. I wonder if there is any easy way to get js.
what I need here is to get the data of a month. First, I need to pass the start and end timestamps of a month, and the backend will judge by this.

Mar.06,2021

it's best to use monent.js

for complex time.
let t = Date.now() - new Date('2018-4-27 10:57:00').getTime()

the old brand usually uses moment.js . However, the Nuggets recently returned a dayjs , which seems to be good.


function computeTime(year, month){
    return [
        new Date(year, month - 1, 1).getTime(),
        new Date(year, month, 0).getTime()
    ]
}
computeTime(2017, 2)

get the time to turn the timestamp

Menu