方式一:推荐使用html
System.currentTimeMillis()
方式二java
new Date().getTime();
方式三spa
Calendar.getInstance().getTimeInMillis();
方式一 > 方式二 > 方式三code
2019/01/09orm
/** * 时间戳转日期 * @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; }