Retrieving Current Moment in ISO 8601 Format with Date, Hour, and Minute
The question posed inquires about the most sophisticated method for obtaining the current moment in ISO 8601 format, specifically UTC, with the desired output being in the format: 2010-10-12T08:50Z.
Elegant Solution
The most elegant solution to this problem is to utilize the SimpleDateFormat class, which allows you to format any Date object. Here's how you can achieve this:
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());
By utilizing a new Date() object as shown above, you can conveniently format the current time in the desired ISO 8601 format.
The above is the detailed content of How Can I Get the Current UTC Time in ISO 8601 Format (YYYY-MM-DDTHH:mmZ)?. For more information, please follow other related articles on the PHP Chinese website!