日付文字列をDate
オブジェクトに変換する方法は?
日付文字列の例:
31.12.2009 23:12:00
var parts = "31.12.2009 23:12:00".match(/\d+/g);
new Date(parts[2], parts[1]-1, parts[0], parts[3], parts[4], parts[5]);
それを解析して作成します。
注: 月はゼロ ベースです。
I recommend the Date.js library.
It can handle all kinds of date parsing and converting, and other date related functionality. Very handy for this kind of thing.
hope that helps.
JavaScriptは、デフォルトでISO8601形式の日付文字列を解析します。
YYYY-MM-DDTHH:mm:ss.sssZ
この形式で日時を取得できるのであれば、おそらくそれが最善でしょう。 文化の問題にぶつかりたくありません。JavaScriptでは、 toISOString() を使用してこれを行うことができます。これができない場合は、自分で日付を解析するか、ライブラリを使用する必要があります。