Java Hour Format formatW3CDateTime(Date date)

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

Description

create a W3C Date Time representation of a date.

License

Apache License

Parameter

Parameter Description
date Date to parse

Return

the W3C Date Time represented by the given Date It returns null if it was not possible to parse the date.

Declaration

public static String formatW3CDateTime(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.*;
import java.util.*;

public class Main {
    /**/*w ww .j a  va 2 s.c  om*/
     * create a W3C Date Time representation of a date.
     * <p/>
     * Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.
     * <p/>
     * 
     * @param date
     *            Date to parse
     * @return the W3C Date Time represented by the given Date It returns <b>null</b> if it was not possible to parse the date.
     */
    public static String formatW3CDateTime(Date date) {
        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        dateFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
        return dateFormater.format(date);
    }

    /**
     * get date string use pattern
     * 
     * @param pattern
     *            see {@link java.text.SimpleDateFormat}
     * @return a date string
     */
    public static String format(String pattern) {
        return format(new Date(), pattern);
    }

    /**
     * get date string use pattern
     * 
     * @param pattern
     *            see {@link java.text.SimpleDateFormat}
     * @return a date string
     */
    public static String format(Date date, String pattern) {
        SimpleDateFormat dateFormater = new SimpleDateFormat(pattern);
        return dateFormater.format(date);
    }
}

Related

  1. formatUIDate(Calendar calendar)
  2. formatUnixFileListing(final Date d)
  3. formatUnsignedVersion(String ver)
  4. formatValue(Object value)
  5. formatVerbose(int level, String message, String source)
  6. formatW3CDateTime(Date date)
  7. formatWCPDate(String date, String sFormat)
  8. formatWithAge(Date date, String dateFormat, String suffix)
  9. formatWithSql92Date(Date date)