Java Long Number to Timestamp longToDate(long timestamp)

Here you can find the source of longToDate(long timestamp)

Description

long To Date

License

Open Source License

Declaration

public static String longToDate(long timestamp) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String longToDate(long timestamp) {
        SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = new Date(timestamp);
        return sfd.format(date1);
    }//w ww . j a v a 2  s  .  c  om

    public static String format(String str, Object... args) {
        if (isEmptyOrNull(str))
            return "";
        if (args.length == 0)
            return str;
        String result = str;
        Pattern p = java.util.regex.Pattern.compile("\\{(\\d+)\\}");
        Matcher m = p.matcher(str);
        while (m.find()) {
            int index = Integer.parseInt(m.group(1));
            if (index < args.length) {
                result = result.replace(m.group(), args[index].toString());
            }
        }
        return result;
    }

    public static boolean isEmptyOrNull(String str) {
        return str == null || str.length() == 0 || str.contentEquals("null") || str.trim().equals("");
    }
}

Related

  1. addSecondsToTimeStamp(Long timestamp, int seconds)
  2. getCompactStringTimestamp(long timestamp)
  3. getIndex(String index, long timestamp)
  4. longToDateTime(long timestamp)
  5. longToDateTime(long timestamp)
  6. prettyPrintDate(long timestamp)
  7. printTimestamp(Long c)