JavaScript-en

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.

 

Pocket
LinkedIn にシェア

  • この記事を書いた人

藤沢瞭介(Ryosuke Hujisawa)

りょすけと申します。18歳からプログラミングをはじめ、今はフロントエンドでReactを書いたり、AIの勉強を頑張っています。off.tokyoでは、ハイテクやガジェット、それからプログラミングに関する情報まで、エンジニアに役立つ情報を日々発信しています!

-JavaScript-en

Copyright© off.tokyo , 2021 All Rights Reserved Powered by AFFINGER5.