1

i have a javascript date object as input data, and i want to have a temporal PlainYearMonth output.

i tried this,

const inputDate = new Date();
    const outputData = Temporal.PlainYearMonth.from(inputDate.toTemporalInstant().toString({smallestUnit: 'minute'}));
    console.log(outputData);

but i get this error,

Uncaught RangeError: Z designator not supported for PlainYearMonth
Justin Grant
  • 44,807
  • 15
  • 124
  • 208

1 Answers1

2

i found a alternative way to get the PlainYearMonth from a instant.

 const inputDate = new Date();
    const outputData = inputDate.toTemporalInstant()
        .toZonedDateTimeISO(timeZone).toPlainYearMonth();
    console.log(outputData);
  • 1
    This is the correct way to do it. Otherwise, suppose for example `const inputDate = new Date(1643673600000);` and your time zone is west of GMT. If the first example were to work, you might expect to get January 2022 as the resulting PlainYearMonth but instead unexpectedly get Februrary 2022. – ptomato Feb 07 '22 at 01:14