newbie newbie - 2 years ago 115
PHP Question

get the ISO 8601 with seconds.decimal-fraction-of-second date in php?

I echo this :

php> echo date("Y-m-d\TH:i:s");

How can do with date function to get this date format:

(for example)

35.7042252 => seconds.decimal-fraction-of-second

I have tried:

php> function getTimestamp()
... {
... return date("Y-m-d\TH:i:s") . substr((string)microtime(), 1, 8);
... }

php> echo getTimestamp();
2011-05-27T15:34:35.6688370 // missing +01:00 how can I do?

Answer Source

u for microseconds was added in PHP 5.2.2. For earlier or (still) broken versions (see comments):

date('Y-m-d\TH:i:s') . substr(microtime(), 1, 8) . date('P')

Or, to avoid two calls to date:

date(sprintf('Y-m-d\TH:i:s%sP', substr(microtime(), 1, 8)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download