Java Date Format formatDate(Date value)

Here you can find the source of formatDate(Date value)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Date value) 

Method Source Code

//package com.java2s;
/**/*from   w w  w .j a v a  2s . com*/
 * Logspace
 * Copyright (c) 2015 Indoqa Software Design und Beratung GmbH. All rights reserved.
 * This program and the accompanying materials are made available under the terms of
 * the Eclipse Public License Version 1.0, which accompanies this distribution and
 * is available at http://www.eclipse.org/legal/epl-v10.html.
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class Main {
    private static final String ISO_8601_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
    private static final String TIMEZONE_UTC = "UTC";

    public static String formatDate(Date value) {
        String formattedValue;
        if (value == null) {
            formattedValue = null;
        } else {
            formattedValue = getTimeFormat().format(value);
        }
        return formattedValue;
    }

    private static DateFormat getTimeFormat() {
        DateFormat df = new SimpleDateFormat(ISO_8601_DATE_FORMAT);
        df.setTimeZone(TimeZone.getTimeZone(TIMEZONE_UTC));
        return df;
    }
}

Related

  1. formatDate(Date myDate)
  2. formatDate(Date pDate, boolean pShowDateOnly)
  3. formatDate(Date t)
  4. formatDate(Date tagValue)
  5. formatDate(Date value)
  6. formatDate(DateFormat format, Date date)
  7. formatDate(final Calendar cal)
  8. formatDate(final Calendar date)
  9. formatDate(final Date dat)