# How to convert milliseconds into human readable form ?

How to convert milliseconds into human readable form ?

• 3 Answer(s)

Using this code for converting milliseconds to human readable form, and it is upto months.

```x = ms / 1000
seconds = x % 60
x /= 60
minutes = x % 60
x /= 60
hours = x % 24
x /= 24
days = x
```

Keep in mind one thing that , always have a awareness of / representation whether it is a integer division or floating point division.

By using modulus operator we can get the solution,

For example,

Take the variable name as var which represents milliseconds,

```seconds=(A/1000)%60
minutes=(A/(1000*60))%60
hours=(A/(1000*60*60))%24
```

We can use the datetime function for achieving this,

```int milliseconds = someNumber;
int seconds = milliseconds / 1000;
int minutes = seconds / 60;
seconds %= 60;
int hours = minutes / 60;
minutes %= 60;
int days = hours / 24;
hours %= 24;
```

• ### Your Answer

By posting your answer, you agree to the privacy policy and terms of service.