0

Let's say I want to create a date-object for 2012 Sep 1st, 10:11:15 h.

I figured out:

past = new Date(2012,08,01,10,11,15);// works!
past = new Date('2012,08,01,10,11,15');// doesn't work.

The problem is, I want to use it in combination with a method:

past = new Date(mypastformatfunc(mystring_to_format));

This gives me NaN. No valid Date-object created. I checked the return of the mypastformatfunc() and it seems I have the right format. Is there any escaping problem regarding quotes? How can I get this to work? It's really strange... Thanks.

EDIT SOLVED: Problem was it wasn't a one value but single parameters. They can't be passed by a function's return at once....

1
  • Can you post the code for mypastformatfunc so we can see exactly what it returns? Commented Sep 13, 2012 at 15:58

1 Answer 1

2

Use the date string as the parameter to the constructor.

past = new Date('2012,08,01,10,11,15'.replace(/(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/, '$1/$2/$3 $4:$5:$6'));

function mypastformatfunc(str) {
  return str.replace(/(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/, '$1/$2/$3 $4:$5:$6')
}
Sign up to request clarification or add additional context in comments.

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.