2

I have an issue using xsd dataTime with regard to integrating a web client written in PHP using LAMP technology with a web service written in C# using WCF technology. The issue has to do with the fact that the two technologies use different, but valid, formats for dateTime.

This issue has been previously posted under Gmt php or UTC C# equivalence through SOAP , but there is no accepted answer.

My issue is that I must convert from the C# Z time format as a string to the alternative UTC dateTime format as a string that can then easily be converted to a PHP DateTime object. I'm hoping someone has a code snippet written in PHP that will do the string conversion. I find it hard to believe that such a code snippet is not readily available given the prevalence of web services an the fact that both WCF and LAMP are popular technologies.

An example of the conversion needed is when given an input, such as '2012-02-04T13:00:00Z', it will produce the correct UTC output, specifically '2012-02-05T00:00:00+11:00'. For details on how this conversion is done, see the accepted answer for xml schema Timezone .

Does anyone have a pointer to a PHP code snippet (or alternatively another language) for the Z time to UTC conversion of a string dateTime?

Community
  • 1
  • 1
J Harri
  • 407
  • 2
  • 7
  • 15

2 Answers2

5

This should be trivial if you set your timezone correctly and format the date to your needs:

$ php -a
php > date_default_timezone_set('Asia/Tokyo');
php > echo date('Y-m-d\TH:i:sP', strtotime('2012-02-04T13:00:00Z'));
2012-02-04T22:00:00+09:00
deceze
  • 510,633
  • 85
  • 743
  • 889
  • If that doesn't help, please explain why. I don't see the problem. :) – deceze Mar 31 '12 at 03:45
  • Yes you are correct. Even though I wrote I wanted the UTC format, I was thinking I wanted the local time format, which I do not know in advance. That is why I said convert 2012-02-04T13:00:00Z to 2012-02-05T00:00:00+11:00. However, actually all I need is the UTC format. – J Harri Mar 31 '12 at 04:18
1

Or maybe something like

$date = new \DateTime("now");
$date->format(\DateTime::RFC3339)]);

as xsd:dateTime is the same as RFCRFC3339

Bery
  • 1,094
  • 1
  • 10
  • 23