2012-03-07 18 views
1

私は文字列Mar 7 2012を持っています。日付の文字列を現在の日付に変換する

これをDateオブジェクトに変換するには、mydate.getDate()mydate.getMonth()mydate.getFullYear()などを使用できますか?

+0

可能重複http://stackoverflow.com/questions/476105/how-can-i-convert-string-to-datetime-with-format-specification-in-javascript – jbabey

+0

可能重複文字列をJavascriptの日付に変換する](http://stackoverflow.com/questions/2769901/how-to-turn-a-string-into-a-date-in-javascript) –

答えて

2

まあ、その非常に単純

var d =new Date("March 7 2012"); 
document.write(d.getMonth()); //use it 
0

私はDate#setTimeと一緒にDate.parseを使用すると思います。たとえば:

var d = new Date(); 
d.setTime(Date.parse("Mar 7 2012")); 

あなたは、Mozillaのdevにかなり良いリファレンスドキュメントをしました。ネットワーク:[どのようにのhttps://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

+1

これで入力が仕様に準拠していないため、偶然に動作しています。 – peller

関連する問題