Java Date Format ISO getIso8601String(Date d)

Here you can find the source of getIso8601String(Date d)

Description

Format a Date into ISO 8601 Complaint format.

License

Open Source License

Return

date string, or empty string if input was null

Declaration

public static String getIso8601String(Date d) 

Method Source Code

//package com.java2s;
/**//  w  ww. j  a v a 2  s.  c  om
 * Copyright (c) 2012 Todoroo Inc
 *
 * See the file "LICENSE" for the full license governing this code.
 */

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz";

    /**
     * Format a Date into ISO 8601 Complaint format.
     * @return date string, or empty string if input was null
     */
    public static String getIso8601String(Date d) {
        SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_FORMAT);
        String result = "";
        if (d != null) {
            result = sdf.format(d);
        }
        return result;
    }
}

Related

  1. getISO8601DateFormat(TimeZone tz, String mask)
  2. getISO8601DateString(Date d)
  3. getIso8601DateString(long timestampWithMilliseconds)
  4. getIso8601DayDateFormat()
  5. getISO8601FormatDate(String in)
  6. getISO8601String(Date date)
  7. getISO8601String(Date date)
  8. getISO8601Time()
  9. getISO8601Time(Date date)