1

Does this date format have any particular name and/or is it used in any particular programming language?

2012-11-28T12:52:22+0000

I need to convert this into JavaScript or PHP date, possibly without using string concatenation.

Kind of what somebody did here: Convert a Unix timestamp to time in JavaScript

Does any of these 2 programming languages have any pre-made function to do so?

Community
  • 1
  • 1
Saturnix
  • 10,130
  • 17
  • 64
  • 120
  • same as this question: http://stackoverflow.com/questions/2002891/what-do-you-call-a-date-time-with-a-t-in-the-middle-2008-09-18t000000 – hinekyle Feb 21 '13 at 20:17
  • well, not exactly the same if you read the answers they're posting here. – Saturnix Feb 21 '13 at 20:19

3 Answers3

5

PHP handles this easily with the DateTime class:

$dt = new DateTime('2012-11-28T12:52:22+0000');
echo $dt->format('Y-m-d');

See it in action

format() accepts the same parameters as date() so you can format it into any format you need.

Reference

John Conde
  • 217,595
  • 99
  • 455
  • 496
3

That's an ISO-8601 date, which is becoming very common on the web.

It is an interoperability format, supported by many frameworks, and was added to PHP in version 5.1.0.

In JavaScript, it is supported by the Date.toISOString() method, and libraries such as Moment.js - among others.

You can construct a JavaScript Date from an ISO string using its constructor:

var date = new Date('2012-11-28T12:52:22+0000');

Be aware that JavaScript is notoriously bad with dates. It only understands dates from a local perspective, or from UTC. Any offset you provide will be merged into the date. That is being worked on in Moment.js. see here.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
2

Yes, it's called an ISO-8601 date. With PHP you generate it with date('c') and with JavaScript:

var date = new Date('2012-11-28T12:52:22+0000');
date.toISOString();

As you can see, the argument to Date() can be just such a string.

silkfire
  • 24,585
  • 15
  • 82
  • 105