var date = '22/04/2020';
console.log(moment(date).format("X"));
log coming as NaN. Please provide a solution for, required output is 1587568445
Try using moment's unix() method. This would give epoch equivalent of "22/04/2020".
Here the time pattern has been removed, hence it results 1587340800 .
For your output, pass in 22/04/2020 20:44:05 to get 1587568445 which is the epoch equivalent
var epoch = moment("22/04/2020", "DD/MM/YYYY").unix(); console.log(epoch); var epoch1 = moment("22/04/2020 20:44:05", "DD/MM/YYYY hh:mm:ss").unix(); console.log(epoch1);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.