0

I want build a function (or using a library) that get the day of the week from a date String..

For example, I want transform this date : 1-12-2015 to "Monday"

Any help ? Thank you

Mohamed Taboubi
  • 6,663
  • 11
  • 55
  • 87
  • [moment.js](http://momentjs.com/), use it – Adam Azad Dec 28 '15 at 17:45
  • You don't need a library for this, Javascript's [Date](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date) methods are perfectly fine for this. In particular see [getDay](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) – Xotic750 Dec 28 '15 at 17:48

1 Answers1

2

var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var day = days[ (new Date("1-12-2015")).getDay() ];
alert(day);
void
  • 36,090
  • 8
  • 62
  • 107