0

Hi I have posted this question before, but people marked it as a duplicate questions. so I didn't get any answer.

I am trying to get the current date/time in the format for example "20150701183741.941Z', I am not sure what the technical term for this format is called. some people told me that it is UTC/ZULU time format.

I have tried generate the above format by using below codes.

date_default_timezone_set("UTC");

echo "formatted currenttime: ".date("YmdHis.ue", time());

but it returns it in the format "20150701144710.000000UTC", this is close to what I need, but I am not able to get at the end something similar to ".941Z".

Please note that this isn't a duplicate question. I posted it earlier but got marked as a duplicate and that one is now inactive. Thanks very much for your help.

special_cheese
  • 160
  • 1
  • 3
  • 14
  • You claim that this is not a duplicate, so I think you should at least link to the previous question and explain what's different. Btw, this is the previous question (and I don't have an opinion on whether it is duplicate or not): http://stackoverflow.com/questions/31164109/convert-date-to-string-in-php-in-the-following-format – yoniLavi Jul 01 '15 at 16:18

2 Answers2

0

The official documentation of date() says that date() always generates 000000 because it takes an integer parameter, and that DateTime() does support microseconds:

http://php.net/manual/en/function.date.php

However, this comment seems to say that DateTime() doesn't support microseconds either:

http://php.net/manual/en/class.datetime.php#108970

So I guess you're out of luck with that :(

0

Why don't you use the Carbon Library? It's one of the superb ways to handle data and time. Just take a look into the official documentation at http://carbon.nesbot.com/docs/

Lajos Mészáros
  • 3,756
  • 2
  • 20
  • 26
tisuchi
  • 129
  • 2
  • 11