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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:33:51+00:00 2026-05-31T15:33:51+00:00

I want to perform a date operation in my android app. What I want

  • 0

I want to perform a date operation in my android app. What I want is to subtract two dates and get the result. But subtraction leads to the wrong result whenever I change the time zone to central daylight time.

I use the following code to find the difference between the two dates.

Long lDateDiff = dtCycleDay.getTime() - m_dtHistory[0].getTime();
lDateDiff = lDateDiff / (1000 * 60 * 60 * 24);

Here in m_dtHistory[0], the date stored is Thu Mar 01 00:00:00 CST 2012.

And in my dtCycleDay variable the date changes from Thu Mar 01 00:00:00 CST 2012, Thu Mar 02 00:00:00 CST 2012, Thu Mar 03 00:00:00 CST 2012… and so on.

Now up to Thu Mar 11 00:00:00 CST 2012, the subtraction result is fine, but when the date changes to Thu Mar 12 00:00:00 CDT 2012, the CST changes to CDT and it show wrong subtraction result.

Why this happens and these happen only when I change the time zone to Central Daylight Time or pacific Daylight Time.

  • 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-31T15:33:53+00:00Added an answer on May 31, 2026 at 3:33 pm

    What do you mean by the “wrong” subtraction result?

    My guess is that the result is 23 hours or 25 hours- which is exactly what I’d expect when a daylight transition occurs, as the intervening day is longer or shorter in terms of elapsed time. The “longer” day won’t be relevant when dividing by 24, but the shorter one will… you’re assuming that every day has 24 hours, and that you can therefore count the number of days by dividing the elapsed milliseconds by “the number of milliseconds in 24 hours”. That doesn’t work due to varying day lengths.

    Don’t forget that a Date value is purely an instant in time. It doesn’t know about calendars or time zones… if you want to know the difference in “local” dates and times (where midnight to midnight is always 24 hours), I’d suggest using Joda Time instead… Date and Calendar don’t really do that for you.

    If the real problem you’re describing is the time zone changing at the wrong date, that’s a different matter entirely, and could be due to various different causes. For one thing, you should show exactly which time zone you’re talking about: the abbreviations are ambiguous, whereas the tzdb names (e.g. “Europe/Paris”) aren’t.

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

Sidebar

Related Questions

i need to perform an operation (in this case DATEDIFF()) on 2 dates. But
I want to perform update operation by joining two different tables. My tables are
I want perform a easy task in android, which when receiving a call the
I want to perform a sort operation on some field. Is it advantageous making
I want to add a debounce to a button, but i want to perform
Here I was trying to perform a GET operation to pull a list of
I have a model called RaceWeek. Two operations I want to perform: (1) I
i want to perform email functionality in my app.In that in subject i have
I want to perform an operation on a array returned from an ActiveRecord query.
how in jQuery work date? I want to perform mathematical operations to date. var

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.