Java Time Format long2String(long longTime, String dataFormat)

Here you can find the source of long2String(long longTime, String dataFormat)

Description

long String

License

Open Source License

Declaration


public static String long2String(long longTime, String dataFormat) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String YYYY_MM_DD = "yyyy-MM-dd";

    public static String long2String(long longTime, String dataFormat) {
        String str = "";
        try {/*www.j a v a  2  s.co m*/
            Date d = new Date(longTime);
            SimpleDateFormat s = new SimpleDateFormat(dataFormat);
            str = s.format(d);
        } catch (Exception e) {
            str = "";
        }
        return str;

    }

    public static String format(Date date, String pattern) {
        if (date == null)
            return "";
        else
            return getFormatter(pattern).format(date);
    }

    public static String format(Date date) {
        if (date == null)
            return "";
        else
            return getFormatter(YYYY_MM_DD).format(date);
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. getUniversalDateTimeFormat()
  2. getXsdDateTimeFormat()
  3. getXSDFormatter(DateTime date)
  4. isDateFormat(String timeString)
  5. long2Datestr(long time, String format)
  6. long2String(long longTime, String dataFormat)
  7. newDateTimeFormat()
  8. printDate(final long time, final String dateFormat)
  9. printFormatDate(long dateTime)