1. The timestamp obtained from the database is of type String. It needs to be compared with the current time to determine whether the login has expired.
Generate the current time of long type, force the String type to long type and report an error. The code is as follows :
long currentTime = System.currentTimeMillis(); //当前时间
// System.out.println("currentTime" + currentTime);
long expireTime = Long.parseLong(token1.getExpireTime()); //过期时间
// System.out.println("expireTime : " + expireTime);
The error message is as follows:
java.lang.NumberFormatException: For input string: "1496733869286 "
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at com.tustcs.matrix.util.Interceptor.preHandle(Interceptor.java:45)
at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:954)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
2. Found that the current time output by the console is wrong
3. The test is as follows:
4. The database information is as follows:
给我你的怀抱2017-06-12 09:29:09
java.lang.NumberFormatException: For input string: "1496733869286 "
You see there is a space behind you.
PS. You don’t call this “String typeforced conversionan error to long type”, the concept is wrong
伊谢尔伦2017-06-12 09:29:09
For input string: "1496733869286 "
Why is there a space after the number?