Already an hour I suffer, it is impossible in any way. Need to translate unix into hours and minutes
- Do I understand correctly that you need to get the value of hours and minutes from the Unix Timestamp? Or do you just need to translate seconds into hours and minutes? - Vladyslav Matviienko September
- Everything turned out, the fact is that the server was already sending in milliseconds) But I didn’t know and multiplied) All answered correctly) - Flippy
- Then it is not Unix Time, but just milliseconds - Vladyslav Matviienko
|
2 answers
To translate the date \ time in the desired format, you can use SimpleDateFormat .
Note that Unix Timestamp is measured in seconds while Date in Java is in milliseconds . That is, in order to convert the Unix Timestamp to the Date , initially you need to multiply the Unix Timestamp by 1000.
Total, to bring your Unix Timestamp in the desired format of 24 hours, you need:
String result = new java.text.SimpleDateFormat("HH:mm").format(new Date(unixTime * 1000)); Please note that "HH:mm" convert to 24-hour format, and "hh:mm" to 12-hour format. You can find out more about formatting in the official documentation.
|
new java.text.SimpleDateFormat("hh:mm").format(new Date(System.currentTimeMillis())) - And where is unix itself in long format to write? - Flippy
- System.currentTimeMillis () - Andrew Bystrov
- In 12 hour format. How in 24? - Flippy
- Nothing happens - Flippy
|