时间戳转换为日期:
public void ChanggeTime(String timeStamp){ SimpleDateFormat sdf= new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); String sd = sdf.format( new Date(Long.parseLong(String.valueOf(timeStamp)))); // 时间戳转换成时间 System. out .println( "格式化结果:" + sd); }
日期转换成时间戳
public void dateToStamp(String s) throws ParseException { String res; SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); Date date = simpleDateFormat.parse(s); long ts = date.getTime(); res = String.valueOf(ts); System. out .println( "格式化结果:" + res); }
获取当前时间戳
//当前系统时间
long now =System.currentTimeMillis();