How to convert timestamp to date in react

藏色散人
Release: 2023-01-19 14:56:11
Original
2790 people have browsed it

React method to convert timestamp to date: 1. Import moment through "import moment from 'moment';"; 2. Use "moment(shijianchuo*1000).format("YYYY-MM-DD HH:mm:ss")" to convert the timestamp into date format.

How to convert timestamp to date in react

The operating environment of this tutorial: Windows 10 system, react18.0.0, Dell G3 computer.

How to convert timestamp to date in react?

React timestamp and date format conversion

1. Convert date to timestamp

1.Import moment

import moment from 'moment';
Copy after login
Copy after login

2. Convert date format to timestamp (millisecond timestamp, conversion to second timestamp requires /1000)

let time_from=parseInt(日期.getTime()/1000)
Copy after login

2. Convert timestamp to date

1.Import moment

import moment from 'moment';
Copy after login
Copy after login

2. Convert timestamp to date format (if it is a second-level timestamp, *1000 is required)

moment(时间戳*1000).format("YYYY-MM-DD HH:mm:ss")
Copy after login

Recommended learning: "react video tutorial"

The above is the detailed content of How to convert timestamp to date in react. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template