2016-09-15 4 views
-1

Moment.jsで日付を正しくフォーマットする際に問題があります。私は "LLL D、YYYY"の形式で書式関数を使用していますので、 "2016年9月15日"のようなものを返してください。Moment.jsの日付をフォーマットする方法

代わりに、「2016年9月15日12:00 AM 15、2016」のような奇妙な形式の日付が返されます。

私のコードは以下のデバッグ情報です。

moment.locale(picker.options.language); 

console.log('picker.options.language:'); 
console.log(picker.options.language); 

formatted = moment(picker.date).format(picker.format); 

console.log('picker.date:'); 
console.log(picker.date); 

console.log('picker.format:'); 
console.log(picker.format); 

console.log('formatted:'); 
console.log(formatted); 

そして、上記のコードからのコンソール出力:私たちは、「LLL」は形式「月の名前、月、年、時間の日」を表していることがわかりますhttp://momentjs.com/docs/#/displaying/format/から

debugging output

答えて

2

。それは "月の日、年"、 "LL"がほしいと思うようです。

試してみてください。(今日の日付を持つ)

picker.format = 'LL'; 
formatted = moment(picker.date).format(picker.format); 
console.log(formatted); 

出力:

September 15, 2016 
+0

が事実を除き、 「LL」の昏睡はないI aggree – user3

+0

ありがとうございました。そのフォーマットは、PHPのIntlDateFormatter :: defaultDateFormats [self :: MEDIUM]からはるか上流に来ていました。 – amacrobert

関連する問題