using moment.js to make your time format nicer

moment.js is a very nice way to handle multiple date strings and output them in a nicer format. 

grab the latest copy of momen from cdnjs

lets say our date is in this format, i think this is unix timestamp


we can pass this date into moment js and it will make it into something actually readable

if you dont want to use an additional library you can also use the toGMTString function which also works. 


<script src=""></script>


// to get the formatted date we still need to pass it through the Date function in javascript
the_date_raw = "1615766400";
// var dateTime = new Date(the_date_raw*1000); /* not sure why this has * 1000 on it, but it seems to require it for a valid date. */
var dateTime = new Date(the_date_raw*1000);
var formatted_date = moment(dateTime).format('MMMM Do YYYY');

// version not using moment.js
var formatted_date_gmt = dateTime.toGMTString();

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
Page Views

This page has been viewed 172 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
Old programmers never die; they just lose some of their functions.