search

Home  >  Q&A  >  body text

Java uses the simplest if to determine whether the date is early or late

The date consists of three int data, namely year, month, day. You cannot use any function, just use the simplest if to judge. Does anyone have any simple method?

Routine: if is nested inside if, if year is equal, determine month, and then determine day
Direct year1000000 month100 day One if can be done

给我你的怀抱给我你的怀抱2743 days ago695

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-17 10:10:33

    Just convert year month day into string, then add them and compare them, just like sorting. Note that month and day must be two digits, and 0 is added for one digit

    reply
    0
  • PHPz

    PHPz2017-05-17 10:10:33

    If you consider the simplicity of the code, then your method is indeed good, but from a performance perspective, three ifs are much more efficient than multiplication

    reply
    0
  • Cancelreply