1

I'm trying to get the first and last day of the month with the format 2016.02.29, but I'm not sure how to turn the date into this format.

The following code (taken from here):

var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

Gives this format: Mon Feb 29 2016 00:00:00 GMT+0100 (W. Europe Standard Time).

How do i make it look like 2016.02.29? I could manipulate the string to get the result I want, but isn't there a way to get it by just defining a format?

Community
  • 1
  • 1
ODIN MEDIA
  • 31
  • 8

1 Answers1

1

You can use the MomentJs to format any date by specifying the exact format.

  1. Load the momentjs or momentjs + locale script in your page
  2. moment().format('YYYY.MM.DD');