2

Hi I have a code like this.

var date = new Date(), y = date.getFullYear(), m = date.getMonth();

var firstDay = new Date(y, m, 1);

The result is like this:

"Thu Sep 01 2016 00:00:00 GMT+0800 (China Standard Time)"

How do I remove the time and other texts so that I'll have a result like this:

"Thu Sep 01"

I already tried .split(' ')[0] and .replace but it says that it is not a function.

Thanks!

Jason P
  • 26,984
  • 3
  • 31
  • 45
jaybee
  • 31
  • 1
  • 2
  • 6

1 Answers1

3

You need to convert the date object to a string, then do your manipulation.

var date = new Date(), y = date.getFullYear(), m = date.getMonth();

var firstDay = new Date(y, m, 1).toString().split(' ').slice(0,3).join(' ');

console.log(firstDay)
j08691
  • 204,283
  • 31
  • 260
  • 272