-1

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

Sora
  • 2,465
  • 18
  • 73
  • 146

2 Answers2

0

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');

DEMO

Eugene Naydenov
  • 7,165
  • 2
  • 25
  • 43
0

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)

whatyouhide
  • 15,897
  • 9
  • 57
  • 71