0

I'm starting off with something that looks like this: 1397773800000

I convert it into something more readable with this:

var time = 1397773800000;
var date = new Date(time);
alert(date); //Thu Apr 17 2014 18:30:00 GMT-0400 (EDT)

However, I want it to be even more readable. I want it to say Thursday, April 17th at 4:30pm EST, for example. And I'm not sure how to separate out each of those components using javascript.

Here's my JSFiddle: http://jsfiddle.net/w4Nbk/

UPDATE: I'm trying out moment.js thanks to a responder, but I can't get it to work in a test JSFiddle: http://jsfiddle.net/w4Nbk/2/

UPDATE #2: Never mind, got it working here: http://jsfiddle.net/yS4da/637/ Could just be that moment.js wasn't called correctly in the fiddle.

1
  • Where "more readable" is subjective. The proposed string has no year and EST is an abbreviation that is used for at least 3 different time zones (and is different to the one in the OP). :-) Commented Apr 11, 2014 at 5:15

1 Answer 1

4

I highly recommend you check out moment.js

It's the perfect tool for all things related to dates and times!


var time = 1397773800000;

moment(time).format('MMMM Do YYYY, h:mm:ss a');
moment(time).format('dddd');
moment(time).format("MMM Do YY");
moment(time).format('YYYY [escaped] YYYY');
moment(time).format();

Output

April 17th 2014, 5:30:00 pm
Thursday
Apr 17th 14
2014 escaped 2014
2014-04-17T17:30:00-05:00
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, do you know why this isn't working in my JSFiddle? jsfiddle.net/w4Nbk/2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.