How to extract the month, day, and year from a timestamp in JavaScript

Today I'll show you how to extract the respective values from a JavaScript typestamp!


If you output data with a timestamp, for example, it will appear in the log like this.


Sun May 30 2021 13:19:06 GMT+0900 (日本標準時)


We want to extract the month, day, and year from this.


However, it is easy.


If you write it like this, you can get it.


console.log(date.getDate()); //returns the date (1-31)
console.log(date.getMonth()); //returns one less than the number of months
console.log(date.getFullYear()); //returns the year


This is what it looks like. I used the following website as a reference.


LinkedIn にシェア

  • この記事を書いた人

藤沢瞭介(Ryosuke Hujisawa)



Copyright© , 2021 All Rights Reserved Powered by AFFINGER5.