Here are a few examples of how to get the timestamp in JavaScript.
Time & Date
Date difference in months
Calculates the difference (in months) between two dates. Use Date.prototype.getFullYear() and Date.prototype.getMonth() to calculate the difference (in months) between two Date objects. Source https://www.30secondsofcode.org/js/s/get-months-diff-between-dates
Unix timestamp from date
Gets the Unix timestamp from a Date object. Use Date.prototype.getTime() to get the timestamp in milliseconds and divide by 1000 to get the timestamp in seconds. Use Math.floor() to appropriately round the resulting timestamp to an integer. Omit the argument, date, to use the current date. Source https://www.30secondsofcode.org/js/s/get-timestamp
Date of yesterday
Results in a string representation of yesterday’s date. Use the Date constructor to get the current date. Decrement it by one using Date.prototype.getDate() and set the value to the result using Date.prototype.setDate(). Use Date.prototype.toISOString() to return a string in yyyy-mm-dd format. Source https://www.30secondsofcode.org/js/s/yesterday
Calculate the difference (in hours) between two dates
Subtract the two Date objects and divide by the number of milliseconds in an hour to get the difference (in hours) between them. Source https://www.30secondsofcode.org/js/s/get-hours-diff-between-dates
Check if a date is the same as another date
Use Date.prototype.toISOString() and strict equality checking (===) to check if the first date is the same as the second one.
Check if the given year is a leap year
Use new Date(), setting the date to February 29th of the given year. Use Date.prototype.getMonth() to check if the month is equal to 1.
Check if the given date is a weekend
Use Date.prototype.getDay() to check weekend by using a modulo operator (%).
How to Add and Subtract Time From a Date in JavaScript
How you can add time to a Date object and subtract time from a Date object in JavaScript.
Get a formatted list of months
Here’s a trick for getting back a formatted month name (like January or Jan).