Here you can find the source of toISO8601FileSystemCompatible(Calendar calendar)
public static String toISO8601FileSystemCompatible(Calendar calendar)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static final String ISO8601_FILESYSTEM = "yyyy-MM-dd'T'HH-mm-ss.SSSZ"; public static String toISO8601FileSystemCompatible(Calendar calendar) { SimpleDateFormat iso8601 = new SimpleDateFormat(ISO8601_FILESYSTEM); iso8601.setTimeZone(calendar.getTimeZone()); String missingDots = iso8601.format(calendar.getTime()).replace("GMT", ""); return missingDots.substring(0, missingDots.length() - 2) + missingDots.substring(missingDots.length() - 2); }/*from w w w. j av a2 s.co m*/ /** * Formats the given {@link Calendar} while considering the time zone * information. * * @param calendar * @param pattern * @return */ public static String format(Calendar calendar, String pattern) { return format(calendar, new SimpleDateFormat(pattern)); } /** * Formats the given {@link Calendar} while considering the time zone * information. * * @param calendar * @param dateFormat * @return */ public static String format(Calendar calendar, DateFormat dateFormat) { dateFormat.setTimeZone(calendar.getTimeZone()); return dateFormat.format(calendar.getTime()); } }