search

Home  >  Q&A  >  body text

java 获取整形时间戳

java中有没有办法获取int型的时间戳,因为之前数据库里是设计成integer的,实体类里也是integer的,所以改起来不方便。只好用int的时间戳
new Date().getTime()、Calendar.getInstance().getTimeInMillis()、System.currentTimeMillis()这三种获取的都是long类型的,有办法获取整型的吗?

阿神阿神2767 days ago317

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:45:34

    Because the database was previously designed to be integer, and the entity class was also integer, so it was inconvenient to change it

    It needs to be changed even if it is inconvenient. If you want to save millisecond timestamps, you must use long,intnot enough.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 17:45:34

    Can’t you handle it yourself?
    For example

    System.currentTimeMillis()/1000

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:45:34

    The timestamp must be of long type. The int type cannot fit the timestamp

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:45:34

    You can use shaping to convert to seconds or minutes, but the accuracy will be lost

    reply
    0
  • Cancelreply