Java Long Number to Time getTimeText(Long oldTime)

Here you can find the source of getTimeText(Long oldTime)

Description

get Time Text

License

Open Source License

Declaration

public static String getTimeText(Long oldTime) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    public final static String TimeFormat = "yyyyMMddHHmmss";
    public final static String DisplayDateFormat = "yyyy-MM-dd";
    public final static String DisplayTimeFormat = "yyyy-MM-dd HH:mm:ss";

    public static String getTimeText(Long oldTime) {
        Date old = parseDate(oldTime, TimeFormat);
        return formatTime(old);
    }//from  ww  w  .  j a v a  2  s. c o m

    public static Date parseDate(Long date, String format) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        try {
            return simpleDateFormat.parse(date + "");
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date parseDate(String date, String format) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        try {
            return simpleDateFormat.parse(date + "");
        } catch (ParseException e) {
            return null;
        }
    }

    public static String formatTime(Date date) {
        return formatDate(date, DisplayTimeFormat);
    }

    public static String formatDate(Date date, String format) {
        if (date == null) {
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        return simpleDateFormat.format(date);
    }

    public static String formatDate(Date date) {
        return formatDate(date, DisplayDateFormat);
    }
}

Related

  1. getTimeStr(long t)
  2. getTimeStr(long timeLong)
  3. getTimeString(long nanoTime)
  4. getTimeString(long time)
  5. getTimeTagged(long time, boolean round)
  6. getUploadPath(String fileName, long time)
  7. logDuration(Logger logger, Level level, long startTime, String message)
  8. long2Str(long time)
  9. longToPgnDate(long time)