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:
trim once and then long
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
For input string: "1496733869286 "
Why is there a space after the number?long i = 1234893584;String s = String.valueOf(i);
turn like this