Java Hour Format format(Date date)

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

Description

format

License

BSD License

Declaration

public static String format(Date date) 

Method Source Code

//package com.java2s;
/**/*from ww  w .  j  a  v a2  s .  c om*/
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */

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

import java.util.TimeZone;

public class Main {
    public static String format(Date date) {
        return format(date, true);
    }

    public static String format(Date date, boolean init) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.'000Z'");
        if (!init)
            sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.'999Z'");
        // We indicate that the returned date is in Zulu time (UTC) so we have
        // to set the time zone of sdf correct.
        sdf.setTimeZone(TimeZone.getTimeZone("ZULU"));
        String ret = sdf.format(date);
        return ret;
    }
}

Related

  1. format(Date date)
  2. format(Date date)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date)
  7. format(Date date)
  8. format(Date date)
  9. format(Date date)