Reputation: 3311
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
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
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