Java Date Format ISO toISO8601FileSystemCompatible(Calendar calendar)

Here you can find the source of toISO8601FileSystemCompatible(Calendar calendar)

Description

to ISO File System Compatible

License

Open Source License

Declaration

public static String toISO8601FileSystemCompatible(Calendar calendar) 

Method Source Code


//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());
    }
}

Related

  1. toISO8601(Date date)
  2. toISO8601(Date date)
  3. toIso8601(Date dateObj)
  4. toIso8601(Date dateTime)
  5. toISO8601(Date pDate)
  6. toISODate(String format, String value)
  7. toISODateRealTimeFormat(Date iDate)
  8. toISOString(Date date, String format, TimeZone tz)
  9. toIsoTime(Date timestamp)