Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set 24-hours format for date on java?

I have been developing Android application where I use this code:

Date d=new Date(new Date().getTime()+28800000); String s=new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").format(d); 

I need to get date after 8 hours from current moment, and I want that this date has 24-hours format, but I don't know how I can make it by SimpleDateFormat. I also need that date has DD/MM/YYYY HH:MM:SS format.

like image 408
user1134602 Avatar asked Jan 18 '12 09:01

user1134602


People also ask

How do I convert a date to 24 hour format?

The pattern dd/MM/yyyy hh:mm:ss aa is used for the 12 hour format and the pattern MM-dd-yyyy HH:mm:ss is used for the 24 hour format.

How do you represent HH MM SS in Java?

SimpleDateFormat(“hh:mm:ss a”) in Java.


1 Answers

for 12-hours format:

SimpleDateFormat simpleDateFormatArrivals = new SimpleDateFormat("hh:mm", Locale.UK); 

for 24-hours format:

SimpleDateFormat simpleDateFormatArrivals = new SimpleDateFormat("HH:mm", Locale.UK); 
like image 180
Tim Kruichkov Avatar answered Sep 23 '22 20:09

Tim Kruichkov