Help us understand the problem. What is going on with this article?

MySQLのTIMESTAMP文字列をJavaScriptでパースするときの注意

More than 5 years have passed since last update.

'2014-02-12 13:16:43' をパースしたい

MySQLのTIMESTAMPは'YYYY-MM-DD HH:MM:SS'の19文字になる。
今なら、'2014-02-12 13:16:43'の形。

これをJavaScriptのDate型にパースするには

// ダメな例
var time = new Date('2014-02-12 13:16:43');

これでOK… じゃない。
WebKit系のブラウザならこれで大丈夫なんだけど、IEやFirefoxでInvaildになる。

Chromeの場合

ScreenShot 2014-02-12 16.44.11.png

Firefoxの場合

ScreenShot 2014-02-12 16.44.56.png

こうする

var time = new Date('2014-02-12 13:16:43'.replace(/-/g, '/'));

IE・Firefoxでもパース出来た。

ScreenShot 2014-02-12 16.48.38.png

詳しくは

JavaScript Dateでパース出来る形式をまとめてくれているナイスなページがあったので、リンクしておく。

http://dygraphs.com/date-formats.html

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away