Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date to specific format in javascript?

Tags:

javascript

Hi i want to convert the current date to a format as follows in javascript: Apr 12, 2011 06:42:03.

Any suggestions?????

like image 786
harishtps Avatar asked Apr 12 '11 15:04

harishtps


1 Answers

Little example I just whipped up for you. Very easy to tell whats going on.

var monthNames = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");

var today = new Date();
var cDate = today.getDate();
var cMonth = today.getMonth();
var cYear = today.getFullYear();

var cHour = today.getHours();
var cMin = today.getMinutes();
var cSec = today.getSeconds();

alert( monthNames[cMonth] + " " +cDate  + "," +cYear + " " +cHour+ ":" + cMin+ ":" +cSec );
like image 145
clamchoda Avatar answered Oct 20 '22 18:10

clamchoda