Java Date Format convertDateToDateString(Date date)

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

Description

Converts an instance of java.util.Date into a String using the date format: yyyy-MM-ddZ.

License

fedora commons license

Parameter

Parameter Description
date Instance of java.util.Date.

Return

Corresponding date string (returns null if Date argument is null).

Declaration

public static String convertDateToDateString(Date date) 

Method Source Code


//package com.java2s;
/* The contents of this file are subject to the license and copyright terms
 * detailed in the license directory at the root of the source tree (also
 * available online at http://fedora-commons.org/license/).
 *///from  w ww .j  a  v  a 2 s. co m

import java.text.DateFormat;

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

public class Main {
    /**
     * Converts an instance of java.util.Date into a String using the date
     * format: yyyy-MM-ddZ.
     *
     * @param date
     *        Instance of java.util.Date.
     * @return Corresponding date string (returns null if Date argument is
     *         null).
     */
    public static String convertDateToDateString(Date date) {
        if (date == null) {
            return null;
        } else {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'Z'");
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            return df.format(date);
        }
    }
}

Related

  1. convertDateToBulgarianFormat(Date date)
  2. convertDateToCustomFormat(Date date, String datePattern)
  3. convertDateToFileName(final Date datum)
  4. convertDateToGMTDateString(Date date)
  5. convertDateToHour(Date d)
  6. convertDateToISO8601(Date date)