CreationTime--2018年7月13日16点29分

Author:Marydon

1.实现方式

  方式一:推荐使用

System.currentTimeMillis()

  方式二

new Date().getTime();

  方式三

Calendar.getInstance().getTimeInMillis();

2.哪个最快?

  方式一 > 方式二 > 方式三

2019/01/09

3.时间戳转日期

/**
 * 时间戳转日期
 * @explain
 * @param timestamp 时间戳可以为String类型,也可以为long类型
 * @return yyyy-MM-dd HH:mm:ss格式字符串
 */
public static String timestampToDate(Object timestamp) {
    long sjc = 0;
    String dateStr = "";
    if (timestamp instanceof String)
        sjc = Long.parseLong((String) timestamp);
    else if (timestamp instanceof Long)
        sjc = (Long) timestamp;
    else 
        return dateStr;
    
    Date date = new Date(sjc);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateStr = sdf.format(date);
    return dateStr;
}

 

 

相关文章:

  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-12
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-05-31
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案