Here you can find the source of formatW3CDateTime(Date date)
public static String formatW3CDateTime(Date date)
//package com.java2s; /**/*from ww w. j ava2 s.c o m*/ * Copyright 2013-2014 Guoqiang Chen, Shanghai, China. All rights reserved. * * Email: subchen@gmail.com * URL: http://subchen.github.io/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.*; import java.util.Date; import java.util.TimeZone; public class Main { public static final String W3C_DATETIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'"; public static String formatW3CDateTime(Date date) { SimpleDateFormat df = new SimpleDateFormat(W3C_DATETIME_PATTERN); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.format(date); } public static String format(String pattern) { return format(new Date(), pattern); } public static String format(Date date, String pattern) { SimpleDateFormat df = new SimpleDateFormat(pattern); return df.format(date); } }