• Welcome to Baben's blog that year. I'm glad to meet you at the right age!
  • Due to the theme, the QQ login partner displays the default avatar in the comments. Please go to the personal center to upload the avatar again.

Js timestamp is converted to normal digital time format

Code Notes barben Four years ago (2020-09-19) 10087 views 1 comment

In the middle of the night, I found that the backend Bring good people The time field passed to me is actually in the format of timestamp???

 Js timestamp format conversion digital format
Originally, I wanted the backend to change the timestamp to a value that can be seen by the male, but when I looked at the time

2020-09-20 02:06:05

Excuse me, I'll do it myself!!!!

 function getdate(time) { var now = new Date(time), y = now.getFullYear(), m = now.getMonth() + 1, d = now.getDate(); return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8); } console.log(getdate(1600413432000)); //  2020-09-18 15:17:12

 


Eight blogs that year, we have been
If the author does not indicate that it is an original article, please indicate the link and source of this article for reprinting
Js timestamp is converted to normal digital time format- https://www.barben.cn/code/897.html
Like( seventeen )
Post my comments
Cancel comment
expression Mapping Bold Strike through Center Italic

You need to bring your nickname and email with you in the review of Eight Books that year!

  • Nickname (required)
  • Email (required)
  • website
Successfully captured one Only rare elves
  1. Now. toTimeString(). substr
    yh 2021-03-29 16:26 reply