How can I convert following date in epoch:
1293683278
to following readable date:
2010-06-23 09:57:58
using Javascript?
Thanks!
Convert from epoch to human-readable dateString date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000)); Epoch in seconds, remove '*1000' for milliseconds. myString := DateTimeToStr(UnixToDateTime(Epoch)); Where Epoch is a signed integer. Replace 1526357743 with epoch.
You can take an epoch time divided by 86400 (seconds in a day) floored and add 719163 (the days up to the year 1970) to pass to it. Awesome, this is as manual as it gets.
To format a date as dd/mm/yyyy: Use the getDate() , getMonth() and getFullYear() methods to get the day, month and year of the date. Add a leading zero to the day and month digits if the value is less than 10 .
var timestamp = 1293683278; var date = new Date(timestamp * 1000); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); console.log(year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds);
See js Date docs for further details
Another way:
var timestamp = 1293683278; var date = new Date(timestamp * 1000); var iso = date.toISOString().match(/(\d{4}\-\d{2}\-\d{2})T(\d{2}:\d{2}:\d{2})/) console.log(iso[1] + ' ' + iso[2]);
You can use moment.js for this.
moment.unix(1293683278).format('YYYY-MM-DD HH:mm:ss');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With