milliseconds to days

前端 未结 5 843
情深已故
情深已故 2020-12-13 03:58

i did some research, but still can\'t find how to get the days... Here is what I got:

int seconds = (int) (milliseconds / 1000) % 60 ;
int minutes = (int) ((         


        
5条回答
  •  生来不讨喜
    2020-12-13 04:01

    If you don't have another time interval bigger than days:

    int days = (int) (milliseconds / (1000*60*60*24));
    

    If you have weeks too:

    int days = (int) ((milliseconds / (1000*60*60*24)) % 7);
    int weeks = (int) (milliseconds / (1000*60*60*24*7));
    

    It's probably best to avoid using months and years if possible, as they don't have a well-defined fixed length. Strictly speaking neither do days: daylight saving means that days can have a length that is not 24 hours.

提交回复
热议问题