Java Long Number to Date formatDateTime(long timestampEpoch)

Here you can find the source of formatDateTime(long timestampEpoch)

Description

format Date Time

License

Mozilla Public License

Declaration

public static String formatDateTime(long timestampEpoch) 

Method Source Code

//package com.java2s;
/**//  www .  j a  va2s  .com
 * 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. formatDateTime(long d)
  2. formatDateTime(long d)
  3. formatDateTime(long date)
  4. formatDateTime(long millis)
  5. formatDateTime(long time)
  6. formatDateTimeStamp(final long timeInMillis, final String dateFormatString)
  7. formateDate(Long date, String format)
  8. formatEpoch(long date)
  9. formatHttpDate(long d)