0

I was looking for this very specific conversion which I couldnt find anywhere

var d = new Date("2014-12-25T18:30:00+0100");
console.log(d.toString());

the console.log returns an "Invalid Date" The DateString is returned by the Facebook GraphAPI.

What am I doing wrong? can anyone help?

Thanks in advance

EDIT:

Now that I fixed the API my output is kind of consfusing:

I tried splitting up the String

d.getDay()+'.'+d.getMonth()+'.'+d.getYear()+' '+d.getHours()+':'+d.getMinutes();

it outputs

4.11.114 18:30

why?!

Max Bumaye
  • 1,017
  • 10
  • 17

2 Answers2

0

Instead of doing those complicated date functions

d.getDate()+'.'+d.getMonth()+'.'+d.getYear()+' '+d.getHours()+':'+d.getMinutes();

Do yourself a favour and include http://momentjs.com/ in your project. You can then simply take the date from the facebook api and format it with

moment("2014-12-25T18:30:00+0100").format("/* date format */");

See here for formating

SIDENOTE

When formating dates in plain javascript, you will have to add 1 month to your month - january is 0, that's why you get 4.11... instead of 4.12...

baao
  • 71,625
  • 17
  • 143
  • 203
  • Please correct the d.getDay() to "d.getDate()" which returns the correct digit - then your answer is perfectly correct :) – Max Bumaye Dec 22 '14 at 21:21
0

Change getYear() to getFullYear()

d.getDay()+'.'+d.getMonth()+'.'+d.getFullYear()+' '+d.getHours()+':'+d.getMinutes();

Jeremy Friesen
  • 383
  • 1
  • 3
  • 13