search

Home  >  Q&A  >  body text

How to compare the size of two String type timestamps in JAVA?

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:

为情所困为情所困2752 days ago1316

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-06-12 09:29:09

    trim once and then long

    reply
    0
  • 给我你的怀抱

    给我你的怀抱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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-12 09:29:09

    For input string: "1496733869286 " Why is there a space after the number?

    reply
    0
  • 代言

    代言2017-06-12 09:29:09

    long i = 1234893584;String s = String.valueOf(i);turn like this

    reply
    0
  • Cancelreply