Home  >  Article  >  Web Front-end  >  How to convert timestamp to date in react

How to convert timestamp to date in react

藏色散人
藏色散人Original
2023-01-19 14:56:112784browse

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';

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

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

2. Convert timestamp to date

1.Import moment

import moment from 'moment';

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")

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!

Statement:
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