(バージョン 1.1.1)で厳密な解決を使用してaLocalDate
から aを解析しようとしています。のような有効な日付ではない入力を受け入れたくありません。しかし、私はそれを理解していません。String
js-joda
2016-05-32
私のコードは次のとおりです。
formatter = (new JSJoda.DateTimeFormatterBuilder)
.appendPattern("yyyy-MM-dd")
.toFormatter(JSJoda.ResolverStyle.STRICT);
JSJoda.LocalDate.parse("2016-05-10", formatter);
そしてエラー:
Text '2016-05-10' could not be parsed: Unable to obtain LocalDate from
TemporalAccessor: [object Object], type DateTimeBuilder: 2016-05-10,
at index: 0
このモードでは、同じコードがResolverStyle.LENIENT
orで期待どおりに機能します。ResolverStyle.SMART
formatter = (new JSJoda.DateTimeFormatterBuilder)
.appendPattern("yyyy-MM-dd")
.toFormatter(JSJoda.ResolverStyle.LENIENT);
JSJoda.LocalDate.parse("2016-05-32", formatter); // result 2016-06-01
で厳密な解決を使用するにはどうすればよいjs-joda
ですか?
更新:
ただし、js-joda DateTimeFormatter APIはこのオプションについて言及していませんuuuu-MM-dd
。@JodaStephen によって提案されたパターンは正常に機能します。ワーキング Js デモ
|記号 |意味 |表現 |使用例 |--------|--------------------------------|----------- -------|--------------- | | ガ | 時代 | 番号/テキスト | 1; 01; 広告; 西暦 | | y | 年 | 年 | 2004; 04 | | D | 年中日 | 数 | 189 | | み | 月 | 年 番号/テキスト | 7; 07; 7月; 7月; J
Java API :
記号 意味 表示例 ------ ------- ------------ ------- G時代のテキストAD。西暦; あ あなたは2004年です。04 y 年号は 2004 年です。04 D 年間通算日番号 189