new Date() set items vs new Date() strings

Edit on GitHub

new Date() set methods vs string creation of the date format

Setup

let day = 1;
let month = 1;
let year = 2017;

Tests

  • new Date() set items

    let reusableDate = new Date();
    
        reusableDate.setHours(0);
        reusableDate.setMinutes(0);
        reusableDate.setSeconds(0);
        reusableDate.setMilliseconds(0);
    
        reusableDate.setYear(year);
        reusableDate.setMonth(month -1);
        reusableDate.setDate(day);
  • new Date() strings

    let reusableDate = new Date(year + '-' + ("0" + month).slice(-2) + '-' + ("0" + day).slice(-2) + 'T00:00:00');