大家好,又见面了,我是你们的朋友全栈君。
/**
* @param s 时间戳
* @return date类型
*/
public static Date timeToDate(String s) {
long lt = new Long(s);
Date date = new Date(lt);
return date;
}
/** date 转时间戳
* @param date
* @return
*/
public static Long getatime(Date date){
return date.getTime();
}
/**
* @param s 时间戳
* @return date字符串
*/
public static String stampToDateString(String s) {
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
public static void main(String[] args) {
//
String s = "1546071846000";
Date date=new Date();
String toString = date.toString();
System.out.println(toString);
long time = date.getTime();
System.out.println(stampToDateString(s));
System.out.println(timeToDate(s));
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151098.html原文链接:https://javaforall.cn