Try the following:
date_default_timezone_set('UTC'); $date = date("Ymd\THis\Z");
The first line sets the default time zone for use in UTC (this is βZβ at the end of the formatted time: Z = "Zulu Time" ). I did this because I donβt know if Google is expecting UTC or not. If you can use other time zones, you can use one of the other available time zone formats .
In the next line, I use date to format the current Unix timestamp (when the timestamp is not passed to date , by default it corresponds to the current time - i.e. time() ). I will make it out for you:
Y - four-digit yearm - Two-digit (including initial zero, if necessary) monthd - two-digit (including the initial zero, if necessary) day of the month\T - The literal character T , which is a separator that defines the beginning of the time part of the date. The slash is the exit from T, because otherwise it is used to display the reduction of the time zone (for example, "PST").H - two-digit (including initial zero, if necessary) houri - two-digit (including leading zero, if necessary) minutes - two-digit (including leading zero, if necessary) second\Z - The literal character Z indicating zulu time, as discussed above. A slash is the exit from T, because otherwise it is used to display the time zone in seconds from UTC.
For reference, and of course, I correctly interpreted the question, this code:
date_default_timezone_set('UTC'); echo date("Ymd\THis\Z", time());
Shows this result:
20110415T014623Z
It should be noted that instead of date() you can use gmdate() and eliminate the need to call date_default_timezone_set() , since gmdate() returns the result in GMT. I am only too shy to mention this because I have never been 100% understandable the difference, if any, between GMT and UTC, especially with other time zones / periods such as BST (British Daylight Saving Time) and how they change GMT if at all. If someone could clarify this in the comments, I would be very grateful.
source share