Java Hour Format format(Date date)

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

Description

Format a Date object as a valid UTC Date String, per OAI-PMH guidelines http://www.openarchives.org/OAI/openarchivesprotocol.html#DatestampsResponses

License

BSD License

Parameter

Parameter Description
date Date object

Return

UTC date string

Declaration

public static String format(Date date) 

Method Source Code

//package com.java2s;
/**//  w  w  w .j a  va  2s  . c om
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */

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

import java.util.TimeZone;

public class Main {
    /**
     * Format a Date object as a valid UTC Date String, per OAI-PMH guidelines
     * http://www.openarchives.org/OAI/openarchivesprotocol.html#DatestampsResponses
     *
     * @param date Date object
     * @return UTC date string
     */
    public static String format(Date date) {
        // NOTE: OAI-PMH REQUIRES that all dates be expressed in UTC format
        // as YYYY-MM-DDThh:mm:ssZ  For more details, see
        // http://www.openarchives.org/OAI/openarchivesprotocol.html#DatestampsResponses
        SimpleDateFormat sdf = new SimpleDateFormat(
                "yyyy-MM-dd'T'HH:mm:ss'Z'");
        // We indicate that the returned date is in Zulu time (UTC) so we have
        // to set the time zone of sdf correctly
        sdf.setTimeZone(TimeZone.getTimeZone("ZULU"));
        String ret = sdf.format(date);
        return ret;
    }
}

Related

  1. format(Date date)
  2. format(Date date)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date)
  7. format(Date date)
  8. format(Date date)
  9. format(Date date)