how can I get this format in javascript:
Saturday,September 21,2013
I did this
var date= new Date();
var d= date.getDate();
but all I am getting is 21 wish is the number of the day
how can I get this format in javascript:
Saturday,September 21,2013
I did this
var date= new Date();
var d= date.getDate();
but all I am getting is 21 wish is the number of the day
I'd suggest you to use a Moment.js library to effectively work with date and time in JavaScript.
var date,
dateString;
date = new Date();
dateString = moment(date).format('dddd, MMMM, DD, YYYY');
You can use the following methods:
var d = new Date();
d.getDate() // returns the number of the day
d.getMonth() // returns the number of the month (starting from 0)
d.getDay() // returns the number of the day in the week
d.getFullYear() // returns the full year, i.e. 2013
In order to use month and day names you can easily write a convertion function:
function nameOfDay(dayNumber) {
return [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
][dayNumber];
}
and a similar one for the months.
(or maybe, if that functionality is very used in your application, you can use an extern library like datejs or Moment.js)