Java Date Format ISO formatIso8601Date(Date date)

Here you can find the source of formatIso8601Date(Date date)

Description

Formats a date into a an ISO 8601 string.

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

returns that date formatted according to the ISO 8601 Date (no time info)

Declaration

public static String formatIso8601Date(Date date) 

Method Source Code

//package com.java2s;
/**//from w  ww  .  j  a va 2  s  . com
 *     This file is part of the Squashtest platform.
 *     Copyright (C) 2010 - 2016 Henix, henix.fr
 *
 *     See the NOTICE file distributed with this work for additional
 *     information regarding copyright ownership.
 *
 *     This is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     this software 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 Lesser General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final String ISO_DATE = "yyyy-MM-dd";

    /**
     * Formats a date into a an ISO 8601 string. <strong>The date will be formatted using the jvm default
     * timezone</strong>
     *
     * @param date
     * @return returns that date formatted according to the ISO 8601 Date (no time info)
     */
    public static String formatIso8601Date(Date date) {
        if (date == null) {
            return null;
        } else {
            return formatDate(date, ISO_DATE);
        }
    }

    private static String formatDate(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}

Related

  1. formatISO8601(Date date, TimeZone timeZone)
  2. formatISO8601(final Date date)
  3. formatISO8601(final Date date)
  4. formatISO8601Date(Date d)
  5. formatISO8601Date(Date date)
  6. formatISO8601Date(Date date)
  7. formatISO8601Date(Date date)
  8. formatISO8601Date(final Calendar date)
  9. formatISO8601Date(final java.util.Date date)