java中时间戳与日期相互转换

long timeStamp = System.currentTimeMillis();//获取当前时间戳(这是毫秒时间戳)

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//这个是你要转成后的时间的格式
String sd = sdf.format(new Date(timeStamp));   // 时间戳转换成时间     (这里也是毫秒时间戳)
System.out.println(sd);//打印出你要的时间                  
 

猜你喜欢

转载自blog.csdn.net/dyfc3sfd3s/article/details/89172949
今日推荐