search

Home  >  Q&A  >  body text

这句Java,为什么会报这个错?

Calendar.getInstance().add(Calendar.DATE, -1).getTime();
报这个错:
Cannot invoke getTime() on the primitive type void

PHPzPHPz2769 days ago337

reply all(4)I'll reply

  • PHPz

    PHPz2017-04-18 09:58:00

    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -1);
    long time = cal.getTime();

    Just write it like this.

    reply
    0
  • PHPz

    PHPz2017-04-18 09:58:00

    Look at the documentation, add() 的返回类型是 void,怎么可能会有 getTime() method

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:58:00

    Calendar.getInstance().add(Calendar.DATE, -1)This sentence returns void

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:58:00

    Builder mode needs to be written by yourself

    reply
    0
  • Cancelreply