Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Moment.js to convert Unix epoch time to human readable time

I'm trying to use Moment.js to convert a Unix epoch time to a date and time. I'd also like to know how to have it formatted like below.

Tuesday, November 22, 2016 6:00 PM

like image 212
danny Avatar asked Nov 22 '16 21:11

danny


People also ask

How do you convert epoch time to human readable?

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.

How do I get epoch time from my moment?

To get a Unix timestamp (the number of seconds since the epoch) from a Moment , use moment#unix .


1 Answers

moment.unix(yourUnixEpochTime).format('dddd, MMMM Do, YYYY h:mm:ss A') 
like image 104
manonthemat Avatar answered Sep 27 '22 17:09

manonthemat