1、获取当前时间并格式化
long currentTime = System.currentTimeMillis();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
Date date = new Date(currentTime);
System.out.println(formatter.format(date));
返回结果
2019年-04月15日-16时34分40秒
2、获取毫秒数时间戳
System.currentTimeMillis();
//1555319032536 13位数
String TimeStampSec = System.currentTimeMillis()/1000; //获取前十时间戳 ,除以1000因为1秒等于1000毫秒
//1555319032 10位数 后面的2相当于2秒的意思 后面增加1秒最后一位就加1
//获得当前的时间的10位时间戳
long newTimeStampSec = System.currentTimeMillis()/1000;
//将截取后的10位时间戳字符串转换我long类型,用来做比较,得到比较后的时间
long timeLen = (newTimeStampSec-TimeStampSec);
//如果不超过60分钟则进入if判断
if(timeLen>=60*60){
map.put("type",-1 );
map.put("msg", "请求超时");
return map;
}