Here you can find the source of toISO8601(Date date)
public static String toISO8601(Date date)
//package com.java2s; /*//from w w w.j av a 2 s . com * ***** BEGIN LICENSE BLOCK ***** * Zimbra Collaboration Suite Server * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software Foundation, * version 2 of the License. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with this program. * If not, see <https://www.gnu.org/licenses/>. * ***** END LICENSE BLOCK ***** */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** Serializes a date in full ISO8601 date/time format. * <pre>yyyy-MM-dd'T'HH:mm:ssZ</pre> */ public static String toISO8601(Date date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String result = format.format(date); // convert YYYYMMDDTHH:mm:ss+HH00 into YYYYMMDDTHH:mm:ss+HH:00 // - note the added colon for the time zone result = result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2); return result; } }