Java Date Format ISO formatIso8601(Date date)

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

Description

Format a date to in ISO 8601 format (as used by GIT) adjusted to UTC timezone.

License

Open Source License

Declaration

public static String formatIso8601(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 Intalio, Inc./*from  w ww.  jav  a 2 s. c o  m*/
 * ======================================================================
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 *   The Eclipse Public License is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 *
 *   The Apache License v2.0 is available at
 *   http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 *******************************************************************************/

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

public class Main {
    public static final TimeZone UTC = TimeZone.getTimeZone("UTC");

    /**
     * Format a date to in ISO 8601 format (as used by GIT) adjusted to UTC timezone.
     */
    public static String formatIso8601(Date date) {
        SimpleDateFormat formatter = createIso8601Format();
        formatter.setTimeZone(UTC);
        return formatter.format(date);
    }

    public static SimpleDateFormat createIso8601Format() {
        // 2011-07-27 11:16:03 +1000
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
    }
}

Related

  1. formatISO8601()
  2. formatIso8601(Date date)
  3. formatIso8601(Date date)
  4. formatISO8601(Date date)
  5. formatISO8601(Date date)
  6. formatISO8601(Date date, TimeZone timeZone)
  7. formatISO8601(final Date date)
  8. formatISO8601(final Date date)
  9. formatISO8601Date(Date d)