Lemon Kazi
Lemon Kazi

Reputation: 3311

React native date convert from int to date

I am new in react-native. I want to convert an int date to a formatted date.

The problem is it's always displaying the current date and not that date from the following integer: 1528101680

This is what I've tried so far:

var newDate = moment(Date(1528101680)).format('MM/DD/YYYY hh:MM');
console.log(newDate);

Upvotes: 2

Views: 9855

Answers (2)

Pranav C Balan
Pranav C Balan

Reputation: 115222

You need to provide time in milliseconds

var newDate = moment(new Date(1528101680 * 1000)).format('MM/DD/YYYY hh:MM');
//                           -----------^^^^^^^------------
console.log(newDate);

var newDate = moment(new Date(1528101680 * 1000)).format('MM/DD/YYYY hh:MM');

console.log(newDate);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>

Upvotes: 4

Kishan Oza
Kishan Oza

Reputation: 1735

try this :

var newDate = moment(1528101680 * 1000).format("MM/DD/YYYY hh:MM") 
console.log(newDate)

var newDate = moment(1528101680 * 1000).format("MM/DD/YYYY hh:MM") 
console.log(newDate)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>

Upvotes: 2

Related Questions