Home    Articles


How to format a given date in javascript



This format will use jQuery UI becouse almost 100% you already have it in your website.

You are probably trying to format a MySql CURRENT_TIMESTAMP date that looks like that: 2015-07-01 18:13:45

Here is the code:

var dateF = '2015-07-01 18:13:45'; // 1'st July 2015
var dateF = dateF.slice(0, 10);  
var dateF = $.datepicker.formatDate("M d, yy", new Date(dateF));

alert(dateF); // will print this: JUL 1, 2015

This code will print this: JUL 1, 2015 .

That's all.