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

  • Home
  • SEARCH
  • 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 9196777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:30+00:00 2026-06-17T21:55:30+00:00

i wandted to conver a long value to formatted time. The code i used:

  • 0

i wandted to conver a long value to formatted time.
The code i used:

long startTimeInSeconds = 60*60*1000*sH + 60*1000*sM + sS*1000 + sL;
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss,SSS");
Date start= new Date(SU.startTime);
StartTime = dateFormat.format(start);

Here sH sM .. are the hours minutes .. from a string, the format was this:"hh:mm:ss,SSS".
SU.startTime is the startTimeInSeconds.
StartTime is a String.

When i display the StartTime it not gives me the correct time.
For example when the startTimeInSeconds is 2510823, it has to be 0:41:50,823 but i get 1:41:50,823.
I dont know what i did wrong, if i display the hours minutes… like this:

int hours = (int) (SU.startTime / (60 * 60 * 1000));

Then i get the correct values.

Does anyone know whats the solution for this problem??

  • 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-06-17T21:55:31+00:00Added an answer on June 17, 2026 at 9:55 pm

    The immediate problem would be fixed by specifying a time zone, as others have suggested. However, a more subtle problem is that you’re using an inappropriate type. You only have a duration, by the sounds of it – or possibly a time of day; it’s unclear. Time zones shouldn’t get involved here, if you can use the right type – after all, a “start time in seconds” doesn’t logically have a time zone related to it.

    Unfortunately Java doesn’t really have the right types to cover this. You’ve got Date and Calendar, neither of which is appropriate. I’d suggest that you use Joda Time instead, where you could use the Duration or LocalTime type based on your requirements – then use an appropriate formatter for that type, and you won’t run into this issue.

    Joda Time is a much better API for date/time handling in general – I would strongly advise using it in preference to the Java API wherever you can.

    EDIT: As noted in comments, you also want HH rather than hh in your format string, as you want the 24 hour clock in order to show midnight as 00 rather than 12.

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

Sidebar

Related Questions

Hi I am having an error running this code Map<String, Integer> map = new
I have a double value 1318611498349.3559, I wanted to convert it to long by
How do I parse non-standard date/time strings in Go. In example if I wanted
I wanted code to convert all the characters in strings to uppercase or lowercase
Wanted to know if someone had a suggestion on code or maybe there's a
I am checking one line of code from my project if ( (test ==
Imagine the following simple code: public void F<T>(IList<T> values) where T : struct {
This will be quite a long way to ask my question, so please bear
I wanted to convert DateTime data which will be pulled from source, to Date
I'm wanted to convert some of my python code to C++ for speed but

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.