Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6254155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:08:10+00:00 2026-05-24T14:08:10+00:00

I am trying to get this string to return Minute:Second:Millisecond for my MediaPlayer. I

  • 0

I am trying to get this string to return Minute:Second:Millisecond for my MediaPlayer. I have found this code, but can’t figure out how to make the Milliseconds work and put it at 2 decimal places. I’m sure its simple to the right person!

private String getTimeString(long millis) {
        StringBuffer buf = new StringBuffer();

        int hours = (int) (millis / (1000*60*60));
        int minutes = (int) (( millis % (1000*60*60) ) / (1000*60));
        int seconds = (int) (( ( millis % (1000*60*60) ) % (1000*60) ) / 1000);


        buf
            .append(String.format("%02d", hours))
            .append(":")
            .append(String.format("%02d", minutes))
            .append(":")
            .append(String.format("%02d", seconds));


        return buf.toString();
    }

Thanks always guys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:08:11+00:00Added an answer on May 24, 2026 at 2:08 pm

    There are 1000 milliseconds in one second, i.e. you’d need 3 decimal places for the milliseconds:

    /** return time in format 1:23.456 */
    private String getTimeString(long millis) {
        int minutes = (int) (millis / (1000 * 60));
        int seconds = (int) ((millis / 1000) % 60);
        int milliseconds = (int) (millis % 1000);
        String.format("%d:%02d.%03d", minutes, seconds, milliseconds);
    }
    

    If you absolutely want 2 digits for milliseconds, you actually get 1/100 seconds and not milliseconds:

    /** return time in format 1:23.45 */
    private String getTimeString(long millis) {
        int minutes = (int) (millis / (1000 * 60));
        int seconds = (int) ((millis / 1000) % 60);
        int seconds100 = (int) ((millis / 10) % 100);
        String.format("%d:%02d.%02d", minutes, seconds, seconds100);
    }
    

    However, a common display format for media players is to use one digit for 10ths of seconds:

    /** return time in format 1:23.4 */
    private String getTimeString(long millis) {
        int minutes = (int) (millis / (1000 * 60));
        int seconds = (int) ((millis / 1000) % 60);
        int seconds10 = (int) ((millis / 100) % 10);
        String.format("%d:%02d.%d", minutes, seconds, seconds10);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying this for quite a while now, but can't figure it out.
I am trying to get the the string this info inside this object lets
Trying to get this expression to work, can someone look at it and tell
Im trying to get this working but for some reason it's just not right.
I am trying to get this piece of code working in C#, what I
i have a simple statement of code that reads: Return String.Format({0} {1} {2}, _var1,
I am trying to get this code to verify that the user input a
I'm trying to run a simple Hibernate application, but I get this error: org.hibernate.exception.SQLGrammarException:
I have been trying to figure this out for the past week and everything
I am trying to get this mapping to work, but I get this strange

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.