I currently have a date which is formatted in PHP like this date('D d F g:i A Y', $l2['available']) which outputs a date in this format: Tue 15 May 5:45 PM 2012
I want to achieve this same format in Javascript/jQuery.
So far I’ve done this:
var lessonTime = new Date(data.lessons[i].available * 1000);
lessonTime.toDateString();
which results in the date below:
Thu Mar 22 2012
Is there a way to control the format like you can with PHP date function?
There’s very little native date formatting in JavaScript, nothing comparable to the PHP formatting capabilities. There are a few libraries that can help with this:
Date.js extends
Date.toString()to accept formatting parametersjQuery has a dateFormat plugin
D3.js has time-formatting support – even if you don’t use the whole library, you could probably use the time formatter by itself.