The query pertains to retrieving the current moment in ISO 8601 format, which follows the structure of "2010-10-12T08:50Z." This format represents a specific moment in time, including the date, hour, minute, and UTC offset.
To achieve this, the preferred approach utilizes the SimpleDateFormat class, which allows for the formatting of any Date object. By specifying a specific format string, you can control the output format.
TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); // Quoted "Z" to indicate UTC, no timezone offset df.setTimeZone(tz); String nowAsISO = df.format(new Date());
In the code, note the following:
The above is the detailed content of How to Get the Current Time in ISO 8601 Format (yyyy-MM-dd\'T\'HH:mm\'Z\')?. For more information, please follow other related articles on the PHP Chinese website!