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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:00:38+00:00 2026-06-12T05:00:38+00:00

I am developing a race timing system, and for several instances, I need to

  • 0

I am developing a race timing system, and for several instances, I need to retrieve a time object from H2DB. Like its bretheren (or sisteren), the time data type is relative to 1st January 1970 and is expressed in SQL in the ‘hh:mm:ss’ format, with the date being by set by default to 01-01-1970. It is by default mapped to the a ‘java.sql.Time’ object. Being a trusting padawan, I coded the following to separate hours from minutes for display purposes.

 if(race.getCutOffTime()!=null){
    long cutOffHour=(race.getCutOffTime().getTime())/(3600000);
    int cutOffMinute=(int)(race.getCutOffTime().getTime()%(60*60*1000));
    System.out.println(cutOffHour+":"+cutOffMinute);
    }

Java’s time handling stink arises however in that these functions output unexpected values, for example, the following statement from my db, gives an output of 3:30.

INSERT INTO MagEye.Races(RaceName, EventID,CutOffTime) 
VALUES ('TEST', SELECT EventID FROM MagEye.Events 
WHERE EventName='Sabrina Love',TIME '5:50:00');

Changing this statement to reflect a time of ‘0:0:0’, gives me a value of “-2:00”
What am I doing wrong? Thank you (in advance).

Edit As requested, here is my code for the database:

Table Creation Statement:

CREATE TABLE IF NOT EXISTS MagEye.Races (RaceID INT PRIMARY KEY AUTO_INCREMENT ,  RaceName VARCHAR(100) ,EventID INT, Description TEXT, MaxEntrants INT, MinAge INT, MaxAge INT, RacePrefix VARCHAR (5), TimingMethod CHAR(1), CutOffTime TIME, RaceEnd TIMESTAMP,Finished BOOLEAN DEFAULT FALSE, Autostart BOOLEAN, FOREIGN KEY(EventID) REFERENCES MagEye.Events(EventID));

Insertion Statement:

INSERT INTO MagEye.Races(RaceName, EventID,CutOffTime) VALUES ('TEST', SELECT EventID FROM MagEye.Events WHERE EventName='Sabrina Love',TIME '5:50:00');

Retrieval:

raceDB.result = raceDB.state.executeQuery("SELECT * FROM MagEye.Races WHERE EventID=" + eventID + " ORDER BY RaceName");
            java.util.ArrayList<Race> races = new java.util.ArrayList<>();


            while (raceDB.result.next()) {
                Race thisRace;
                String timingMethodString = raceDB.result.getString("TimingMethod");
                Race.TimingMethod timingMethod = null;
                if (timingMethodString != null) {
                    timingMethod = Race.TimingMethod.valueOf(timingMethodString);
                } else {
                    timingMethod = Race.TimingMethod.MANUAL;
                }
                thisRace = new Race(raceDB.result.getInt("RaceID"), event, raceDB.result.getString("RaceName"), raceDB.result.getString("Description"), raceDB.result.getInt("MaxEntrants"), raceDB.result.getInt("MinAge"), raceDB.result.getInt("MaxAge"), raceDB.result.getString("RacePrefix"), timingMethod,(raceDB.result.getTime("CutOffTime")), raceDB.result.getBoolean("Autostart"));
thisRace = new Race(raceDB.result.getInt("RaceID"), event, raceDB.result.getString("RaceName"), raceDB.result.getString("Description"), raceDB.result.getInt("MaxEntrants"), raceDB.result.getInt("MinAge"), raceDB.result.getInt("MaxAge"), raceDB.result.getString("RacePrefix"), timingMethod,(raceDB.result.getTime("CutOffTime")), raceDB.result.getBoolean("Autostart"));

Display:

if(race.getCutOffTime()!=null){
    long cutOffHour=(int)(race.getCutOffTime().getTime())/(3600000);
    RacesCutOffLength.setText(cutOffHour+"");      
    int cutOffMinute=(int)(race.getCutOffTime().getTime()%(60*60*1000));
    this.RacesMinutes.setText(cutOffMinute+"");
    }
    else{
        RacesCutOffLength.setText("0");      
        RacesMinutes.setText("0");      
    }

Edit: I’ve decided to replace the Time object with a long primative

  • 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-12T05:00:40+00:00Added an answer on June 12, 2026 at 5:00 am

    java.util.Date is always the UTC time. So, depending of your locale, there will be probably an offset.

    I have heard of Joda Time as a better Java API for dealing with times.

    Anyway, the problem comes from mixing dates treated by java.util.Date and others directly passed as part of the SQL.

    As long as you keep using java.util/sql.Date for everything (and you don’t peak inside the DB)(and you don’t change the locale) the results will be coherent. The trouble will begin when your SQL tries to pass the values directly as text. So either use Date everywhere or, as trashgod says, everytime you use a Date you take care of setting the Locale to “GMT” (so the internal representation and the output of the Date are the same). Note that this does include Date returned from the DB

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

Sidebar

Related Questions

I'm developing an app that has a model using race results / times etc..
Developing a project of mine I realize I have a need for some level
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
For developing an devices monitor system, I am using a InetAdress isReachable method to
Developing a new ROR3 website, I need to implement a sort of internal mail
Developing for iPhone, I have a collection of points that I need to make
Developing an app where all tabular data is returned as an object. Some cells
Developing a Struts 2 app I run in a following problem. I need to
After developing in PHP for a long time I have decided to step into
Developing locally in MAMP and need Sphinx to work with MAMP's MySQL. Basically hitting

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.