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 6103033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:40:57+00:00 2026-05-23T13:40:57+00:00

What is the most efficient method of converting an int val to its string

  • 0

What is the most efficient method of converting an int val to its string counterpart in this format – “HH:MM:SS”

10 becomes 00:00:10
70 becomes 00:01:10
3610 becomes 01:00:10

I need this to be JDK1.4 compliant.

What I’ve come up with is a series of if statements and then constructing a string based on the current int val. This is not very efficient. Is there a better way?

  • 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-23T13:40:58+00:00Added an answer on May 23, 2026 at 1:40 pm

    Instead of a heap of code, how about just one line?

    String time = new SimpleDateFormat("HH:mm:ss")  
        {{setTimeZone(TimeZone.getTimeZone("UTC"));}}.format(new Date(3610 * 1000)); // "01:00:10"
    

    p.s. I never fails to amaze me just how much code some people write to do the simplest of things

    The timezone is set to UTC, because SimpleDateFormat uses your locale to format the date. For example my timezone is GMT+10 and if I format new Date(0), the time part is “10:00:00”.

    For those who don’t recognise that odd syntax where the timezone is being set, it’s an anonymous class with an “instance block”, which gets executed on construction, after the constructor has finished.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is running a nested NSScanner the most efficient method for parsing out a string
Is this most efficient method to box/unbox multidimensional primitive arrays in Java without using
Just wondering if this is the most efficient method of doing this? is there
What would be the most efficient method of reading a text file into a
What's the most efficient way to convert the output of this function from a
What is the most efficient method of showing my data in descending order? public
I'm looking for the most efficient method of flipping the sign on all four
What is most efficient method to making sure that get/post parameters won't provide any
What is the most efficient method to store a Python dictionary on the disk?
What's the most efficient method of implementing a shared data object between multiple JInternalFrames

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.