Comment convertir l’horodatage unix en calendrier date.js

J’ai un horodatage Unix, et j’essaie de le convertir en une date de calendrier telle que MM / JJ / AAAA. Jusqu’à présent, j’ai ceci:

$(document).ready(function() { var value = $("#unixtime").val(); //this resortingeves the unix timestamp var dateSsortingng = moment(value).calendar(); alert(dateSsortingng); }); 

Lorsque j’essaie d’imprimer la date du calendrier, la fenêtre indique “Date non valide”. Quelqu’un peut m’aider?

En utilisant moment.js comme vous l’avez demandé:

 var dateSsortingng = moment.unix(value).format("MM/DD/YYYY"); 

L’horodatage UNIX correspond au nombre de secondes depuis 1970, vous devez donc le convertir en object JS Date:

 var date = new Date(unixTimestamp*1000); 

Moment.js fournit des formats localisés pouvant être utilisés.

Voici un exemple:

 const moment = require('moment'); const timestamp = 1519482900000; const formatted = moment(timestamp).format('L'); console.log(formatted); // "02/24/2018" 
 new moment(timeStamp,'yyyyMMddHHmmssfff').toDate()