Java Date getTime function returns negative value

后端 未结 1 852
遥遥无期
遥遥无期 2021-01-13 03:13

I\'m converting a String to a date, then converting it integer value to make the comparison between dates easier. Here\'s my code:

SimpleDateFormat format =          


        
1条回答
  •  时光说笑
    2021-01-13 03:52

    date.getTime() returns a long. If you cast it to int, it may become negative due to overflow.

    If you change your code to :

    long lastModifiedDate =  date.getTime();
    

    You'll get a positive value - 1317580706000 - which can't fit in an int variable.

    0 讨论(0)
提交回复
热议问题