Here you can find the source of formatW3CDateTime(Date date)
Parameter | Description |
---|---|
date | Date to parse |
public static String formatW3CDateTime(Date date)
//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); } }