Date object to Temporal PlainYearMonth

265 Views Asked by At

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
1

There are 1 best solutions below

1
Julian Kragt On BEST ANSWER

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);