datetime()
datetime(input, zone?): DateTime
datetime(input, options?): DateTime文字列、タイムスタンプ、フィールドオブジェクト、またはカレンダー日付を読み取り、指定したタイムゾーンで解釈された DateTime を作成します。タイムゾーンを省略すると、設定済みのデフォルトまたは実行環境のローカルタイムゾーンが使われます。
import { date, datetime } from 'native-dates';
const fromUtc = datetime('2026-11-16T17:30:00Z', 'America/Los_Angeles');
const fromWall = datetime('2026-11-16 09:30', 'Europe/Berlin');
const fromZone = datetime('2026-11-16T09:30[America/New_York]');
const fromEpoch = datetime(1794850200000, 'UTC');
const fromDate = datetime(date('2026-11-16'), 'America/New_York');引数
ISO 文字列、エポックミリ秒、Date、フィールドオブジェクト、カレンダー日付、または Temporal の値。
'Europe/Berlin' や 'UTC' のようなタイムゾーン文字列、またはオプションオブジェクト。
4件のオプション
時点を解釈・表現するタイムゾーン。input に含まれる角括弧 [...] 内のタイムゾーンより優先。
返される DateTime とそこから派生するすべての値に引き継がれる BCP 47 ロケールタグ。
false@native-dates/plugins/loose を使用し、非定型の日付文字列を解析して読み取れない入力には null を返す設定。
loose モードで '07/09/2026' のような数値日付を解析する際、アクティブなロケールの並び順を上書きする設定。
戻り値
解決されたタイムゾーン上の DateTime。loose モードで input を読み取れない場合は null。
@native-dates/plugins/loose をインポートすると、loose モードではアクティブなロケールで非定型の日付・時刻を読み取り、機械向け形式はエンジンの解析にフォールバックします。読み取れない入力に対しては null を返します。
import { datetime } from 'native-dates';
import '@native-dates/plugins/loose';
datetime('Mon, 16 Nov 2026 17:30:00 GMT', { zone: 'America/New_York', loose: true });
datetime('not a timestamp', { loose: true }); // null