2

console.log of my initial date shows:

Fri Apr 01 2016 02:00:00 GMT+0200 (CEST)

This is what I do:

  // first day is guaranteed to be a first day of month by default
  var firstDayOfMonth = moment.utc(initialDate).startOf('day');
  var lastDayOfMonth = firstDayOfMonth.clone();
  lastDayOfMonth.endOf('month');
  console.log(firstDayOfMonth.toDate()); // Fri Apr 01 2016 02:00:00 GMT+0200 (CEST)
  console.log(lastDayOfMonth.toDate()); // Sun May 01 2016 01:59:59 GMT+0200 (CEST)

But last day of April is not May 1st of course.

It might be related to a Summertime issue (CEST)? But i need it working in any timezone - I already try to set anything as UTC to get rid of these annoying timezone issues.

LBA
  • 3,859
  • 2
  • 21
  • 60

1 Answers1

4

Use moment.format() instead of toDate() to get in UTC. For different formats refer Multiple Locale Support here https://momentjs.com/

For example,

console.log(lastDayOfMonth.format('LLLL')); 

output: Saturday, April 30, 2016 11:59 PM
RaR
  • 3,075
  • 3
  • 23
  • 48