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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:10:56+00:00 2026-06-01T01:10:56+00:00

I have a train schedule app, and I am trying to calculate the difference

  • 0

I have a train schedule app, and I am trying to calculate the difference between two times with the following format HH:MM, so my users can easily see if the train is late (note: I am fetching the “real” data from the internet, so it is up-to-date). This is what I am doing at the moment:

    //schedule time of the train
    int hs=12;
    int ms=0;

    //real time of the train
    int hr=12;
    int mr=15;

    int t1=hs*60 + ms;
    int t2=hr*60 + mr;

    int d; //integer for the difference in minutes
    if(hr>=hs) d=t2-t1; //standard situation
    else d=1440+t2-t1; //for situation like sch: 23:55, real: 00:05

Is this correct? Am I forgetting anything? I had a few tries before this algorithm, all of them had minor bugs, which could confuse my users. As far as I see, this one does not have any glitch, at least I couldn’t find any.

P.S.: I won’t use any 3rd party libs, so I have to write my own algorithm, tho I hope it will be the final…

Thx!

EDIT: note: the values of hs/ms/hr/mr are hardcoded in this example, tho in my app, I have them updated correctly, for each row.

  • 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-01T01:10:57+00:00Added an answer on June 1, 2026 at 1:10 am

    This should give you the minute difference on any day, or over the border of any day, except for daylight savings time.

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

Sidebar

Related Questions

I have a database for a Train company. I want to combine two queries
We have a DSL , how can we calculate the available bandwidth so that
I have the following java code: nameFinderModel = NameFinderME.train(en, organization, sampleStream, Collections.<String, Object>emptyMap()); And
Ok, I have the following code to train the NER Identifier from OpenNLP FileReader
I have two tables that look like this Train +----------+-------------+------+-----+---------+-------+ | Field | Type
I have a database of bus/train/... stops and the arrival/departure times on each date
I have a data structure which represents a train, which can be made up
I'm developing simple image sharing site to train my ruby-on-rails-fu. I have following resources
I have table in data base name train delay, with columns train number(int), DelayTime(int),
Supose we have a very simple model: Station has at least one Train Train

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.