i am trying to output "900,000 milliseconds" in the format "days:hours:minutes:seconds" and I am using this code right now:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd:HH:mm:ss");
String formatted = simpleDateFormat.format(900000)
900,000 milliseconds should be 15 minutes, so I want it to return
00:00:15:00
or something like this...
But for any reason it returns
01:01:15:00
Can anybody tell me why and how to fix it?
I thought it had to do something with time zones, but it added 1 to the number of days as well...?
Thanks in advance!
Class SimpleDateFormat. Deprecated. A class for parsing and formatting dates with a given pattern, compatible with the Java 6 API.
Return Value: The method returns Date or time in string format of mm/dd/yyyy.
Java SimpleDateFormat Example String pattern = "MM-dd-yyyy"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); String date = simpleDateFormat. format(new Date()); System. out. println(date);
The java SimpleDateFormat allows construction of arbitrary non-localized formats. The java DateFormat allows construction of three localized formats each for dates and times, via its factory methods.
Day is 01 because it stands for 01 January. Hour 01 may be related to your time zone. Try this:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd:HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String formatted = simpleDateFormat.format(900000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With