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

1615766400

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. 

Scripts

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

Javascript

// 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');
console.log(formatted_date);

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

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
 
Page Views

This page has been viewed 212 times.

Search Code
Search Code by entering your search text above.
Welcome

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
You drown not by falling in the river, but by staying submerged.
Unknown