Last Updated: February 25, 2016
·
1.535K
· barbagallo

Format UTC Timestamp To Human Readable

Sometimes formatting dates sucks, so here's an easy starter function for formatting your dates!

/**
* formatPostDate - returns a string of the correct date format given a UTC timestamp.
* e.g. 12.25.2012
*
* @param dateString
*/
var formatPostDate = function(dateString){
    var tempDateObj = new Date(dateString),
        retDateString = '';

        retDateString = (tempDateObj.getMonth()+1) + '.' + tempDateObj.getDate() + '.' + tempDateObj.getFullYear();

        return retDateString;
};

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside