Documentation and Books

Recent site activity

Web Development‎ > ‎JavaScript‎ > ‎

How do I convert the number of milliseconds since January 1, 1970, 00:00:00 into its corresponding date (dd/mm/yy format)?

The following JavaScript method provides this functionality:

<html>
<head>
<script language="JavaScript">

function convertMillisecondsToFormattedDate(milliseconds) {
var date = new Date(milliseconds);
var day = date.getDate();
var month = date.getMonth()+1;
var year = getFullYear();

return day + '/' + month + '/' + year;
}
</script>
</head>
<body>
<input type="button" value="display date"
onclick="alert(convertMillisecondsToFormattedDate(925241310748));"/>
</body>
</html>

Notice that you have to pass a Date object into the daysElapsed method and not String values.