long s=System.currentTimeMillis();long s1=newDate().getTime();long s2=Calendar.getInstance().getTimeInMillis();long s3=Instant.now().toEpochMilli();long s4=Clock.systemUTC().millis();
将时间戳转化为指定格式的日期:
String s ="1662460000000";//设置时间的格式SimpleDateFormat f =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");//将时间转换指定格式的日期String date=f.format(Long.valueOf(s));System.out.println(date);
将指定格式的时间转化为时间戳
String s ="2020-09-09 12:12:00";SimpleDateFormat f=newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");//getTime()获取格式日期的时间戳long shootTime = f.parse(s).getTime();System.out.println(shootTime);