Here you can find the source of formatISODate(Date date)
Parameter | Description |
---|---|
date | the date to format. |
public static String formatISODate(Date date)
//package com.java2s; /*/*from ww w . j ava 2 s .c o m*/ * Copyright (c) 2012. betterFORM Project - http://www.betterform.de * Licensed under the terms of BSD License */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { /** * Returns a date formatted according to ISO 8601 rules. * * @param date the date to format. * @return the formmatted date. */ public static String formatISODate(Date date) { // always set time zone on formatter TimeZone timeZone = TimeZone.getDefault(); boolean utc = TimeZone.getTimeZone("UTC").equals(timeZone) || TimeZone.getTimeZone("GMT").equals(timeZone); String pattern = utc ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ssZ"; SimpleDateFormat format = new SimpleDateFormat(pattern); format.setTimeZone(timeZone); StringBuffer buffer = new StringBuffer(format.format(date)); if (!utc) { buffer.insert(buffer.length() - 2, ':'); } return buffer.toString(); } }