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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:26:39+00:00 2026-06-06T11:26:39+00:00

I got a countdown that counts down to a specific date. Each tick (interval

  • 0

I got a countdown that counts down to a specific date. Each tick (interval 1 second) updates a textbox with the days/hours/minutes left until the event. My problem is that the minutes (don’t know about the days/hours yet) keeps flickering. Meaning it says 18 then 17 then 18 then 17 during the minute before going down to 16 then 17 then 16 and it continues to do like that.

Flickering problem solved, now its just the timezone that is not working. (Flickering was solved using the code from Pshemo)

Also the TimeZone doesn’t appear to be working. It shows 2 hours to much. Have tried to change it using SimpleTimeZone but it doesn’t work, still showing the +2 hours (regardless of the settings on SimpleTimeZone)

What could be the cause?

Countdown code:

         new CountDownTimer(remaining, 1000) {
         TextView tv = (TextView)getActivity().findViewById(R.id.introTimeLeft);
         public void onTick(long millisUntilFinished) {         
             SimpleTimeZone ts = new SimpleTimeZone(2, "Middle Europe");

             Calendar cal = Calendar.getInstance(ts);
             cal.set(2012, 5, 28, 17, 0);
             long endTime = cal.getTimeInMillis(); 
             long currentTime = System.currentTimeMillis();
             long remaining = endTime - currentTime;

         tv.setText(getDurationBreakdown(remaining));
         }

         ...

      }.start();

public String getDurationBreakdown(long millis)
{
    if(millis < 0)
    {
        throw new IllegalArgumentException("Duration must be greater than zero!");
    }

    long days = TimeUnit.MILLISECONDS.toDays(millis);
    millis -= TimeUnit.DAYS.toMillis(days);

    long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);

    long minutes = (long) Math.ceil(TimeUnit.MILLISECONDS.toMinutes(millis));

    StringBuilder sb = new StringBuilder(64);
    sb.append(days);
    sb.append(" Days ");
    sb.append(hours);
    sb.append(" Hours ");
    sb.append(minutes);
    sb.append(" Minutes");

    return(sb.toString());
}
  • 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-06T11:26:40+00:00Added an answer on June 6, 2026 at 11:26 am

    It is just wild guess but no charm in trying it.

    From what I see you read currentTime and endTime in same place.

    long endTime = cal.getTimeInMillis(); 
    long currentTime = System.currentTimeMillis();
    

    You also don’t specify milliseconds in calendar object so cal.getTimeInMillis() is using current milliseconds. So your code

    long remaining = endTime - currentTime;
    

    will sometimes be equal to value like 183360000 but also sometimes it will be equalt to value like 182999999 (depending on how many milliseconds passed between creation endTime and currentTime).

    This can lead to 1 milliseconds miscalculations but after rounding, it can be also 1 sec/min/hour/day (if this values will be changing in next millisecond).

    You can solve it by reading endTime only once, and updating only currentTime while calculating remaining

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

Sidebar

Related Questions

I have got a piece of code, that should countdown some number (in this
I've got a TextView that I would like to count down (3...2...1...stuff happens). To
I'm trying to show a timer to the user that counts down from 3
I've written an updatescript that updates a few div's every second with serverside info.
I've got a database of ~10 million entries, each of which contains a date
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
Got issue My javascript array contains dates for ex. 19.4.2003,28.11.1997,3.1,,29.6,7.11.2008 (date-month-year). As you can
I've got some Android code that works fine to make a piece of text
Does anyone have an idea how to make a countdown ticker that shows the
I've got an application that requires the time until an event (in seconds) to

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.