Java Hour Format formatW3CDateTime(Date date)

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

Description

format WC Date Time

License

Open Source License

Declaration

public static String formatW3CDateTime(Date date) 

Method Source Code

//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);
    }
}

Related

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