6

I would like to create a valid JavaScript Date object from the following string "010-10-25T23:25:55.847Z".

This string comes out of a PostGIS database "timestamp with time zone" Data Type field.

Anyone know how i can do this?

Fail: *Edit:*Sorry, i had bad date string:

var startDate = new Date("2010-10-30T14:10:42.377Z");

EDIT #2: This works fine now with the RIGHT date string.... sorry.

var startDate = new Date("2010-10-30T14:10:42.377Z");
5
  • 1
    What is that date? Oct 25th 1910? Commented Aug 12, 2011 at 15:07
  • @Joey: sorry i had bad date string please see edit. 2010-10-30T14:10:42.377Z Commented Aug 12, 2011 at 15:20
  • The answer you accepted gives you the complete wrong answer. It could be confusing for people searching this in the future. Commented Aug 12, 2011 at 17:57
  • @Joey: how is it wrong? jsfiddle.net/gU77h It looks right to me. Commented Aug 12, 2011 at 18:13
  • not your solution, but Mark Davies is wrong, which you marked as correct. Yours is correct. Commented Aug 12, 2011 at 18:17

2 Answers 2

1

User strtotime.

These links might help:

Sign up to request clarification or add additional context in comments.

Comments

1

I'm not sure what that format it, but this will give you each number:

var results = "010-10-25T23:25:55.847Z".match(/\d+\.{0,1}\d+/g);
var year = results[0]; // maybe ?
var month = results[1];
var day = results[2];
var etc...;
new Date(year, --month, day, hour, minutes, seconds);

or if it's kinda like UTC,

new Date(Date.UTC.apply(this, "010-10-25T23:25:55.847Z".match(/\d+\.{0,1}\d+/g)))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.