The code:
function format_date( date, index )
{
if ( !date || ( index && !( date[ index ] ) ) )
{
return '';
}
console.log( date );
var date = new Date(
( index === undefined ) ? date : date[ index ]
);
console.log( date );
return ( date.getMonth() + 1 ) + '/' +
date.getDate() + '/' +
date.getFullYear() + ' 12:00 AM'
;
};
format_date( "2013-07-25" );
Output:
2013-07-25
Date {Wed Jul 24 2013 20:00:00 GMT-0400 (Eastern Standard Time)}
"7/24/2013 12:00 AM"
This is on a node JS server running on Linux. The output from date is:
Fri Aug 2 10:39:28 EDT 2013
new Date(...)is considered GMT, while you are usinggetDate()instead ofgetUTCDate()when manually parsing?Date. Moment.js will make your life much easier. Even if you only use pieces of it.