1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Cookie cookie = CookieUtils.getCookie(request.getCookies(), "lastTime"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (null == cookie) { Date date = new Date(); System.out.println("第一次访问时间:" + sdf.format(date)); cookie = new Cookie("lastTime", String.valueOf(date.getTime())); } else { long currTimeMills = Long.parseLong(cookie.getValue()); System.out.println("上一次访问时间:" + sdf.format(new Date(currTimeMills))); cookie.setValue(String.valueOf((new Date()).getTime())); } response.addCookie(cookie);
|