Java Hour Format formatDateTime(Calendar cal)

Here you can find the source of formatDateTime(Calendar cal)

Description

format Date Time

License

Mozilla Public License

Declaration

public static String formatDateTime(Calendar cal) 

Method Source Code

//package com.java2s;
/**/*  w w  w . j  a v a 2 s  .co  m*/
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
 * obtain one at http://mozilla.org/MPL/2.0/.
 *
 * If it is not possible or desirable to put the notice in a particular file,
 * then You may include the notice in a location (such as a LICENSE file in a
 * relevant directory) where a recipient would be likely to look for such a
 * notice.
 *
 * 
 */

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Calendar;

public class Main {
    private static final SimpleDateFormat dtg = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    public static String formatDateTime(Calendar cal) {
        synchronized (dtg) {
            if (cal == null) {
                return "unknown";
            }
            return dtg.format(cal.getTime());
        }
    }

    public static String formatDateTime(Date cal) {
        synchronized (dtg) {
            if (cal == null) {
                return "unknown";
            }
            return dtg.format(cal);
        }
    }

    public static String formatDateTime(long timestampEpoch) {
        synchronized (dtg) {
            return dtg.format(new Date(timestampEpoch));
        }
    }
}

Related

  1. formatDateRfc822(Date date, String timeZoneId)
  2. formatDateString(Date d)
  3. formatDateString(String dateString)
  4. formatDateString2(String str_date)
  5. formatDateTime()
  6. formatDateTime(Calendar dateTime)
  7. formatDateTime(Calendar time)
  8. formatDateTime(Date d)
  9. formatDateTime(Date d)