SimpleDateFormat mm:ss format - minutes get padded with a 3









up vote
1
down vote

favorite












I have the weirdest problem - In our app, at one place we are showing a time formatted with mm:ss, using SimpleDateFormat. The problem is we have a client in US that complains that they get 5min formatted as 35:00. I narrowed it down that SimpleDateFormat.format is called with the same value that I'm testing with, but they are getting minutes padded with 3 instead of 0.



The thing is I'm not able to replicate the problem and they are telling me they tested and are getting it on 4 different devices:



  • Oppo X9076 (Android 5.0)

  • Xiaomi Mi A1(Android 8.1.0)

  • Samsung SM-T715Y(Android 7.0)

  • HUAWEI BLA-L29 (Android 8.0)

I'm also, testing on the Xiaomi Mi A1 (and few other), but the time is ok when I try.



This is how the time is formated:



SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
timeFormatter.format(new Date(5*60*1000));


Does anyone have seen something like this?










share|improve this question

















  • 1




    As an aside consider throwing away the long outmoded and notoriously troublesome SimpleDateFormat and friends, and adding ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with. And I would consider it likely to eliminate your error.
    – Ole V.V.
    Nov 9 at 8:23







  • 1




    Are your using SimpleDateFormat for formatting a duration? That’s — you may call it misuse, incorrect, inappropriate or against intentions depending on taste. Find inspiration here: How to format a duration in java? (e.g format H:MM:SS) instead.
    – Ole V.V.
    Nov 9 at 8:30










  • Is 11 minutes rendered as 11 or 41? 0 minutes as 30 or 33? Have you got other clients in the same US time zone, and if you have, have they got the same problem or not?
    – Ole V.V.
    Nov 9 at 8:34














up vote
1
down vote

favorite












I have the weirdest problem - In our app, at one place we are showing a time formatted with mm:ss, using SimpleDateFormat. The problem is we have a client in US that complains that they get 5min formatted as 35:00. I narrowed it down that SimpleDateFormat.format is called with the same value that I'm testing with, but they are getting minutes padded with 3 instead of 0.



The thing is I'm not able to replicate the problem and they are telling me they tested and are getting it on 4 different devices:



  • Oppo X9076 (Android 5.0)

  • Xiaomi Mi A1(Android 8.1.0)

  • Samsung SM-T715Y(Android 7.0)

  • HUAWEI BLA-L29 (Android 8.0)

I'm also, testing on the Xiaomi Mi A1 (and few other), but the time is ok when I try.



This is how the time is formated:



SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
timeFormatter.format(new Date(5*60*1000));


Does anyone have seen something like this?










share|improve this question

















  • 1




    As an aside consider throwing away the long outmoded and notoriously troublesome SimpleDateFormat and friends, and adding ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with. And I would consider it likely to eliminate your error.
    – Ole V.V.
    Nov 9 at 8:23







  • 1




    Are your using SimpleDateFormat for formatting a duration? That’s — you may call it misuse, incorrect, inappropriate or against intentions depending on taste. Find inspiration here: How to format a duration in java? (e.g format H:MM:SS) instead.
    – Ole V.V.
    Nov 9 at 8:30










  • Is 11 minutes rendered as 11 or 41? 0 minutes as 30 or 33? Have you got other clients in the same US time zone, and if you have, have they got the same problem or not?
    – Ole V.V.
    Nov 9 at 8:34












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have the weirdest problem - In our app, at one place we are showing a time formatted with mm:ss, using SimpleDateFormat. The problem is we have a client in US that complains that they get 5min formatted as 35:00. I narrowed it down that SimpleDateFormat.format is called with the same value that I'm testing with, but they are getting minutes padded with 3 instead of 0.



The thing is I'm not able to replicate the problem and they are telling me they tested and are getting it on 4 different devices:



  • Oppo X9076 (Android 5.0)

  • Xiaomi Mi A1(Android 8.1.0)

  • Samsung SM-T715Y(Android 7.0)

  • HUAWEI BLA-L29 (Android 8.0)

I'm also, testing on the Xiaomi Mi A1 (and few other), but the time is ok when I try.



This is how the time is formated:



SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
timeFormatter.format(new Date(5*60*1000));


Does anyone have seen something like this?










share|improve this question













I have the weirdest problem - In our app, at one place we are showing a time formatted with mm:ss, using SimpleDateFormat. The problem is we have a client in US that complains that they get 5min formatted as 35:00. I narrowed it down that SimpleDateFormat.format is called with the same value that I'm testing with, but they are getting minutes padded with 3 instead of 0.



The thing is I'm not able to replicate the problem and they are telling me they tested and are getting it on 4 different devices:



  • Oppo X9076 (Android 5.0)

  • Xiaomi Mi A1(Android 8.1.0)

  • Samsung SM-T715Y(Android 7.0)

  • HUAWEI BLA-L29 (Android 8.0)

I'm also, testing on the Xiaomi Mi A1 (and few other), but the time is ok when I try.



This is how the time is formated:



SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
timeFormatter.format(new Date(5*60*1000));


Does anyone have seen something like this?







java android simpledateformat






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 8:13









Mit_

8917




8917







  • 1




    As an aside consider throwing away the long outmoded and notoriously troublesome SimpleDateFormat and friends, and adding ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with. And I would consider it likely to eliminate your error.
    – Ole V.V.
    Nov 9 at 8:23







  • 1




    Are your using SimpleDateFormat for formatting a duration? That’s — you may call it misuse, incorrect, inappropriate or against intentions depending on taste. Find inspiration here: How to format a duration in java? (e.g format H:MM:SS) instead.
    – Ole V.V.
    Nov 9 at 8:30










  • Is 11 minutes rendered as 11 or 41? 0 minutes as 30 or 33? Have you got other clients in the same US time zone, and if you have, have they got the same problem or not?
    – Ole V.V.
    Nov 9 at 8:34












  • 1




    As an aside consider throwing away the long outmoded and notoriously troublesome SimpleDateFormat and friends, and adding ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with. And I would consider it likely to eliminate your error.
    – Ole V.V.
    Nov 9 at 8:23







  • 1




    Are your using SimpleDateFormat for formatting a duration? That’s — you may call it misuse, incorrect, inappropriate or against intentions depending on taste. Find inspiration here: How to format a duration in java? (e.g format H:MM:SS) instead.
    – Ole V.V.
    Nov 9 at 8:30










  • Is 11 minutes rendered as 11 or 41? 0 minutes as 30 or 33? Have you got other clients in the same US time zone, and if you have, have they got the same problem or not?
    – Ole V.V.
    Nov 9 at 8:34







1




1




As an aside consider throwing away the long outmoded and notoriously troublesome SimpleDateFormat and friends, and adding ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with. And I would consider it likely to eliminate your error.
– Ole V.V.
Nov 9 at 8:23





As an aside consider throwing away the long outmoded and notoriously troublesome SimpleDateFormat and friends, and adding ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with. And I would consider it likely to eliminate your error.
– Ole V.V.
Nov 9 at 8:23





1




1




Are your using SimpleDateFormat for formatting a duration? That’s — you may call it misuse, incorrect, inappropriate or against intentions depending on taste. Find inspiration here: How to format a duration in java? (e.g format H:MM:SS) instead.
– Ole V.V.
Nov 9 at 8:30




Are your using SimpleDateFormat for formatting a duration? That’s — you may call it misuse, incorrect, inappropriate or against intentions depending on taste. Find inspiration here: How to format a duration in java? (e.g format H:MM:SS) instead.
– Ole V.V.
Nov 9 at 8:30












Is 11 minutes rendered as 11 or 41? 0 minutes as 30 or 33? Have you got other clients in the same US time zone, and if you have, have they got the same problem or not?
– Ole V.V.
Nov 9 at 8:34




Is 11 minutes rendered as 11 or 41? 0 minutes as 30 or 33? Have you got other clients in the same US time zone, and if you have, have they got the same problem or not?
– Ole V.V.
Nov 9 at 8:34












1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










It’s a time zone problem. Or more precisely, a problem of misusing SimpleDateFormat for something that it wasn’t meant for. Here’s a way you can reproduce:



 TimeZone.setDefault(TimeZone.getTimeZone("America/St_Johns"));
SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
System.out.println(timeFormatter.format(new Date(5*60*1000)));


Output from this snippet is:




35:00




Explanation:
new Date(5*60*1000) produces a date-time of 5 minutes after the epoch, that is 00:05:00 UTC on January 1, 1970. At this time as at any other time, different zones of the world have different times. However, most time zones have an offset from UTC of a whole number of hours. So the time will be 5 minutes past the hour, and your formatter will print it as 05:00. This is why you didn’t notice the problem before. For example, in Berlin it will be 01:05:00, and in New York it will be 19:05:00 the evening before. However, there are also time zones that have offsets from UTC that are not a whole number of hours. For example Asia/Kolkata is at +05:30 and Asia/Kathmandu is at +05:45. In such a time zone, the time will not be 5 minutes past the hour, and you will get an unexpected result like the one you saw.



Suggested solutions include:



  • Use TimeUnit for converting seconds into minutes and seconds and String.format for formatting them into two digits each.

  • If you want a nice solution and you’re OK with an external dependency on an old library in maintenance mode, look into the PeriodFormatter of Joda-Time.

Here’s an example of using TimeUnit for calculating the parts to format as suggested in the first bullet:



 long totalSeconds = TimeUnit.MINUTES.toSeconds(5); // 300

long minutes = TimeUnit.SECONDS.toMinutes(totalSeconds);
long secondsPart = totalSeconds - TimeUnit.MINUTES.toSeconds(minutes);
String formattedDuration = String.format("%02d:%02d", minutes, secondsPart);
System.out.println("Formatted duration: " + formattedDuration);


Output:




Formatted duration: 05:00




The ugly hack that I wouldn’t suggest would be to set the time zone of your formatter to UTC.



There’s a lot more inspiration in the question I already linked to in a comment. At time of writing it has 20 answers. I am repeating the link at the bottom.



And by the way, even for formatting and parsing dates and times, you may consider not using SimpleDateFormat. It’s notoriously troublesome and long outmoded. Instead add ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with.



Links




  • Joda-Time home page.


  • Stack Overflow question: How to format a duration in java? (e.g format H:MM:SS).


  • Oracle tutorial: Date Time explaining how to use java.time.


  • Java Specification Request (JSR) 310, where java.time was first described.


  • ThreeTen Backport project, the backport of java.time to Java 6 and 7 (ThreeTen for JSR-310).


  • ThreeTenABP, Android edition of ThreeTen Backport


  • Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.





share|improve this answer






















  • Great answer, It helped a lot!
    – Mit_
    Nov 19 at 12:30










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221986%2fsimpledateformat-mmss-format-minutes-get-padded-with-a-3%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










It’s a time zone problem. Or more precisely, a problem of misusing SimpleDateFormat for something that it wasn’t meant for. Here’s a way you can reproduce:



 TimeZone.setDefault(TimeZone.getTimeZone("America/St_Johns"));
SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
System.out.println(timeFormatter.format(new Date(5*60*1000)));


Output from this snippet is:




35:00




Explanation:
new Date(5*60*1000) produces a date-time of 5 minutes after the epoch, that is 00:05:00 UTC on January 1, 1970. At this time as at any other time, different zones of the world have different times. However, most time zones have an offset from UTC of a whole number of hours. So the time will be 5 minutes past the hour, and your formatter will print it as 05:00. This is why you didn’t notice the problem before. For example, in Berlin it will be 01:05:00, and in New York it will be 19:05:00 the evening before. However, there are also time zones that have offsets from UTC that are not a whole number of hours. For example Asia/Kolkata is at +05:30 and Asia/Kathmandu is at +05:45. In such a time zone, the time will not be 5 minutes past the hour, and you will get an unexpected result like the one you saw.



Suggested solutions include:



  • Use TimeUnit for converting seconds into minutes and seconds and String.format for formatting them into two digits each.

  • If you want a nice solution and you’re OK with an external dependency on an old library in maintenance mode, look into the PeriodFormatter of Joda-Time.

Here’s an example of using TimeUnit for calculating the parts to format as suggested in the first bullet:



 long totalSeconds = TimeUnit.MINUTES.toSeconds(5); // 300

long minutes = TimeUnit.SECONDS.toMinutes(totalSeconds);
long secondsPart = totalSeconds - TimeUnit.MINUTES.toSeconds(minutes);
String formattedDuration = String.format("%02d:%02d", minutes, secondsPart);
System.out.println("Formatted duration: " + formattedDuration);


Output:




Formatted duration: 05:00




The ugly hack that I wouldn’t suggest would be to set the time zone of your formatter to UTC.



There’s a lot more inspiration in the question I already linked to in a comment. At time of writing it has 20 answers. I am repeating the link at the bottom.



And by the way, even for formatting and parsing dates and times, you may consider not using SimpleDateFormat. It’s notoriously troublesome and long outmoded. Instead add ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with.



Links




  • Joda-Time home page.


  • Stack Overflow question: How to format a duration in java? (e.g format H:MM:SS).


  • Oracle tutorial: Date Time explaining how to use java.time.


  • Java Specification Request (JSR) 310, where java.time was first described.


  • ThreeTen Backport project, the backport of java.time to Java 6 and 7 (ThreeTen for JSR-310).


  • ThreeTenABP, Android edition of ThreeTen Backport


  • Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.





share|improve this answer






















  • Great answer, It helped a lot!
    – Mit_
    Nov 19 at 12:30














up vote
4
down vote



accepted










It’s a time zone problem. Or more precisely, a problem of misusing SimpleDateFormat for something that it wasn’t meant for. Here’s a way you can reproduce:



 TimeZone.setDefault(TimeZone.getTimeZone("America/St_Johns"));
SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
System.out.println(timeFormatter.format(new Date(5*60*1000)));


Output from this snippet is:




35:00




Explanation:
new Date(5*60*1000) produces a date-time of 5 minutes after the epoch, that is 00:05:00 UTC on January 1, 1970. At this time as at any other time, different zones of the world have different times. However, most time zones have an offset from UTC of a whole number of hours. So the time will be 5 minutes past the hour, and your formatter will print it as 05:00. This is why you didn’t notice the problem before. For example, in Berlin it will be 01:05:00, and in New York it will be 19:05:00 the evening before. However, there are also time zones that have offsets from UTC that are not a whole number of hours. For example Asia/Kolkata is at +05:30 and Asia/Kathmandu is at +05:45. In such a time zone, the time will not be 5 minutes past the hour, and you will get an unexpected result like the one you saw.



Suggested solutions include:



  • Use TimeUnit for converting seconds into minutes and seconds and String.format for formatting them into two digits each.

  • If you want a nice solution and you’re OK with an external dependency on an old library in maintenance mode, look into the PeriodFormatter of Joda-Time.

Here’s an example of using TimeUnit for calculating the parts to format as suggested in the first bullet:



 long totalSeconds = TimeUnit.MINUTES.toSeconds(5); // 300

long minutes = TimeUnit.SECONDS.toMinutes(totalSeconds);
long secondsPart = totalSeconds - TimeUnit.MINUTES.toSeconds(minutes);
String formattedDuration = String.format("%02d:%02d", minutes, secondsPart);
System.out.println("Formatted duration: " + formattedDuration);


Output:




Formatted duration: 05:00




The ugly hack that I wouldn’t suggest would be to set the time zone of your formatter to UTC.



There’s a lot more inspiration in the question I already linked to in a comment. At time of writing it has 20 answers. I am repeating the link at the bottom.



And by the way, even for formatting and parsing dates and times, you may consider not using SimpleDateFormat. It’s notoriously troublesome and long outmoded. Instead add ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with.



Links




  • Joda-Time home page.


  • Stack Overflow question: How to format a duration in java? (e.g format H:MM:SS).


  • Oracle tutorial: Date Time explaining how to use java.time.


  • Java Specification Request (JSR) 310, where java.time was first described.


  • ThreeTen Backport project, the backport of java.time to Java 6 and 7 (ThreeTen for JSR-310).


  • ThreeTenABP, Android edition of ThreeTen Backport


  • Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.





share|improve this answer






















  • Great answer, It helped a lot!
    – Mit_
    Nov 19 at 12:30












up vote
4
down vote



accepted







up vote
4
down vote



accepted






It’s a time zone problem. Or more precisely, a problem of misusing SimpleDateFormat for something that it wasn’t meant for. Here’s a way you can reproduce:



 TimeZone.setDefault(TimeZone.getTimeZone("America/St_Johns"));
SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
System.out.println(timeFormatter.format(new Date(5*60*1000)));


Output from this snippet is:




35:00




Explanation:
new Date(5*60*1000) produces a date-time of 5 minutes after the epoch, that is 00:05:00 UTC on January 1, 1970. At this time as at any other time, different zones of the world have different times. However, most time zones have an offset from UTC of a whole number of hours. So the time will be 5 minutes past the hour, and your formatter will print it as 05:00. This is why you didn’t notice the problem before. For example, in Berlin it will be 01:05:00, and in New York it will be 19:05:00 the evening before. However, there are also time zones that have offsets from UTC that are not a whole number of hours. For example Asia/Kolkata is at +05:30 and Asia/Kathmandu is at +05:45. In such a time zone, the time will not be 5 minutes past the hour, and you will get an unexpected result like the one you saw.



Suggested solutions include:



  • Use TimeUnit for converting seconds into minutes and seconds and String.format for formatting them into two digits each.

  • If you want a nice solution and you’re OK with an external dependency on an old library in maintenance mode, look into the PeriodFormatter of Joda-Time.

Here’s an example of using TimeUnit for calculating the parts to format as suggested in the first bullet:



 long totalSeconds = TimeUnit.MINUTES.toSeconds(5); // 300

long minutes = TimeUnit.SECONDS.toMinutes(totalSeconds);
long secondsPart = totalSeconds - TimeUnit.MINUTES.toSeconds(minutes);
String formattedDuration = String.format("%02d:%02d", minutes, secondsPart);
System.out.println("Formatted duration: " + formattedDuration);


Output:




Formatted duration: 05:00




The ugly hack that I wouldn’t suggest would be to set the time zone of your formatter to UTC.



There’s a lot more inspiration in the question I already linked to in a comment. At time of writing it has 20 answers. I am repeating the link at the bottom.



And by the way, even for formatting and parsing dates and times, you may consider not using SimpleDateFormat. It’s notoriously troublesome and long outmoded. Instead add ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with.



Links




  • Joda-Time home page.


  • Stack Overflow question: How to format a duration in java? (e.g format H:MM:SS).


  • Oracle tutorial: Date Time explaining how to use java.time.


  • Java Specification Request (JSR) 310, where java.time was first described.


  • ThreeTen Backport project, the backport of java.time to Java 6 and 7 (ThreeTen for JSR-310).


  • ThreeTenABP, Android edition of ThreeTen Backport


  • Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.





share|improve this answer














It’s a time zone problem. Or more precisely, a problem of misusing SimpleDateFormat for something that it wasn’t meant for. Here’s a way you can reproduce:



 TimeZone.setDefault(TimeZone.getTimeZone("America/St_Johns"));
SimpleDateFormat timeFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
System.out.println(timeFormatter.format(new Date(5*60*1000)));


Output from this snippet is:




35:00




Explanation:
new Date(5*60*1000) produces a date-time of 5 minutes after the epoch, that is 00:05:00 UTC on January 1, 1970. At this time as at any other time, different zones of the world have different times. However, most time zones have an offset from UTC of a whole number of hours. So the time will be 5 minutes past the hour, and your formatter will print it as 05:00. This is why you didn’t notice the problem before. For example, in Berlin it will be 01:05:00, and in New York it will be 19:05:00 the evening before. However, there are also time zones that have offsets from UTC that are not a whole number of hours. For example Asia/Kolkata is at +05:30 and Asia/Kathmandu is at +05:45. In such a time zone, the time will not be 5 minutes past the hour, and you will get an unexpected result like the one you saw.



Suggested solutions include:



  • Use TimeUnit for converting seconds into minutes and seconds and String.format for formatting them into two digits each.

  • If you want a nice solution and you’re OK with an external dependency on an old library in maintenance mode, look into the PeriodFormatter of Joda-Time.

Here’s an example of using TimeUnit for calculating the parts to format as suggested in the first bullet:



 long totalSeconds = TimeUnit.MINUTES.toSeconds(5); // 300

long minutes = TimeUnit.SECONDS.toMinutes(totalSeconds);
long secondsPart = totalSeconds - TimeUnit.MINUTES.toSeconds(minutes);
String formattedDuration = String.format("%02d:%02d", minutes, secondsPart);
System.out.println("Formatted duration: " + formattedDuration);


Output:




Formatted duration: 05:00




The ugly hack that I wouldn’t suggest would be to set the time zone of your formatter to UTC.



There’s a lot more inspiration in the question I already linked to in a comment. At time of writing it has 20 answers. I am repeating the link at the bottom.



And by the way, even for formatting and parsing dates and times, you may consider not using SimpleDateFormat. It’s notoriously troublesome and long outmoded. Instead add ThreeTenABP to your Android project in order to use java.time, the modern Java date and time API. It is so much nicer to work with.



Links




  • Joda-Time home page.


  • Stack Overflow question: How to format a duration in java? (e.g format H:MM:SS).


  • Oracle tutorial: Date Time explaining how to use java.time.


  • Java Specification Request (JSR) 310, where java.time was first described.


  • ThreeTen Backport project, the backport of java.time to Java 6 and 7 (ThreeTen for JSR-310).


  • ThreeTenABP, Android edition of ThreeTen Backport


  • Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 2:56

























answered Nov 9 at 8:45









Ole V.V.

25.8k62550




25.8k62550











  • Great answer, It helped a lot!
    – Mit_
    Nov 19 at 12:30
















  • Great answer, It helped a lot!
    – Mit_
    Nov 19 at 12:30















Great answer, It helped a lot!
– Mit_
Nov 19 at 12:30




Great answer, It helped a lot!
– Mit_
Nov 19 at 12:30

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221986%2fsimpledateformat-mmss-format-minutes-get-padded-with-a-3%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus