DateTime Formatting

DateTime values are expected to be in the ISO 8601 format, for example '2013年02月14日T13:15:03-08:00' (YYYY-MM-DDTHH:mm:ssZ).

Below are examples for generating ISO 8601 datetime strings in a few popular programing languages.

Java

Datedate=newDate();
DateFormatdf=newSimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
StringdateAsISOString=df.format(date);

JavaScript

vard=newDate();
vardate=d.toISOString();

PHP

$objDateTime = new DateTime('NOW');
$isoDate = $objDateTime->format(DateTime::ISO8601);

Python

fromdatetimeimport date
d = date.now()
date = d.isoformat()

Ruby

require'time'
d=Time.now
date=d.utc.iso8601

Perl

my$now=time();
$date=time2isoz($now);

C++

time_tnow;
time(&now);
charbuf[sizeof"2011-10-08T07:07:09Z"];
strftime(buf,sizeofbuf,"%FT%TZ",gmtime(&now));

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年03月24日 UTC.