How to convert timestamp in react.js?

Viewed 861

So this is my data November 30, 2021 at 12:00:00 PM UTC+7 how would it convert it into something like this November 30, 2021?

4 Answers

according to your question,if your data is the all the format like November 30, 2021 at 12:00:00 PM UTC+7, you can just split the data by blank or at symbol,why not do it simply

If you're open to using other libraries, the moment.js one is pretty well documented and thorough.

Here is a short sample of what I recently used in my code, using moment.js

import moment from 'moment';

let convertedDate = moment(date)
return convertedDate.format("LLL") // this returns December 15, 2021 10:38 AM

Your case may be rather:

moment().format('LL');   // December 15, 2021

There are a lot of different format types, check them here

You can use the built-in toLocaleDateString function to easily convert any date into your desired output by passing options to it.

const options = { year: "numeric", month: 'long', day: 'numeric' };
console.log(new Date().toLocaleDateString('en-US', options));

Related