-1

How can I convert Javascript Date Objects to a date string in the following format:

Date Object

2000-01-12 23:00:00.000Z

Resulting String

"01/12/2000 23"
8
  • 2
    Can you show us what you have tried? Commented Feb 6, 2014 at 8:57
  • 1
    Try: (new Date('2000-01-12 23:00:00.000Z')).toLocaleString() Commented Feb 6, 2014 at 8:59
  • 1
    @tewathia - '2000-01-12 23:00:00.000Z' isn't a valid date string. Commented Feb 6, 2014 at 9:02
  • 1
    @Frogmouth I did try it in the console, in Chrome V32. I get >(new Date('2000-01-12 23:00:00.000Z')).toLocaleString(); >"1/13/2000 4:30:00 AM". Also, see jsfiddle.net/tewathia/X7LMP Commented Feb 6, 2014 at 9:14
  • 1
    @tewathia ... I believe you, but not seems cross browser :D Commented Feb 6, 2014 at 9:17

1 Answer 1

3
date.getDate() + '/' +
(date.getMonth() +1) + '/' + 
date.getFullYear() + ' ' +
(date.getHours() + 1)

Why the +1 you ask? Because javascript. :(

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.