yearMonth()
yearMonth(input, options?): YearMonth
yearMonth(input, zone?): YearMonth
yearMonth(year, month): YearMonth연-월 순 문자열, 연도와 1부터 시작하는 월 숫자, 필드 객체, 또는 날짜·타임스탬프(일은 제외)로부터 YearMonth를 생성합니다. 입력이 누락되면 이번 달로 대체하지 않고 TypeError를 던집니다.
import { datetime, yearMonth } from 'native-dates';
const fromIso = yearMonth('2026-11');
const fromNumbers = yearMonth(2026, 11);
const fromFields = yearMonth({ year: 2026, month: 11 });
const fromDate = yearMonth('2026-11-16');
const fromInstant = yearMonth(datetime('2026-11-01T02:00:00Z'), 'America/Los_Angeles');
fromNumbers.toString(); // '2026-11'
fromInstant.toString(); // '2026-10'매개변수
ISO 연-월 문자열, 필드 객체, 날짜·타임스탬프 또는 달력 연도(year).
타임스탬프나 비정형 문자열을 읽을 때의 시간대·옵션 객체 또는 1부터 12까지의 월(month).
옵션 3개
시점 문자열, DateTime 또는 Date에서 달력 월을 판별할 때 사용할 시간대.
반환된 YearMonth와 이 값에서 파생되는 모든 값에 유지할 BCP 47 로케일 태그.
false@native-dates/plugins/loose와 함께 'février 2026' 같은 영어·현지화 월명을 읽고 파싱할 수 없으면 null을 반환하는 옵션.
반환값
일(day) 정보가 없는 YearMonth, 또는 느슨한 모드에서 input을 읽을 수 없을 때 null.
loose 플러그인을 불러오면 느슨한 모드에서 4자리 연도와 함께 쓰인 영어 또는 활성 locale의 월명을 파싱하고, 읽을 수 없는 문자열에는 null을 반환합니다.
import { yearMonth } from 'native-dates';
import '@native-dates/plugins/loose';
yearMonth('Nov 2026', { loose: true })?.toString(); // '2026-11'
yearMonth('février 2026', { loose: true, locale: 'fr' })?.toString(); // '2026-02'
yearMonth('not-a-month', { loose: true }); // null