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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:00:11+00:00 2026-06-12T00:00:11+00:00

What I am trying to do is a basic alarm app on Android. When

  • 0

What I am trying to do is a basic alarm app on Android. When I set date and time via UI (say 2012-09-26 at 14:37) I want the alarm go off at that time regardless of the timezone. That setting is serialized as two separate values – date value and offset from the beginning of the day in milliseconds.

I also made a mistake of using Joda library for date/time manipulation. The API confused me by looking very similar to .NETs DateTime API, but still suffering from the same duality issue as default Java framework APIs, where the object value is in UTC, but its properties are in local time (this concept blows my mind btw). It also seems to have trouble picking up Android’s time zone change automatically.

This is a summary of what I have:

// part of reminder class
public DateTime getNextAlarm()
{
    DateTime now = DateTime.now();
    DateTime next = date.withMillisOfDay(time);
    while (next.compareTo(now) <= 0)
        next = next.plusDays(repeat);
    return next;
}

// inside worker thread
workerEnabled = true;
while (workerEnabled)
{
    try
    {
        Thread.sleep(10000);
    }
    catch (InterruptedException e)
    {
        workerEnabled = false;
        return;
    }

    DateTimeZone tz = DateTimeZone.forTimeZone(TimeZone.getDefault());
    if (nextAlarm != null && nextAlarm.withZoneRetainFields(tz).compareTo(new DateTime(tz)) < 0)
    {
        nextAlarm = reminder.getNextAlarm();

        // perform alarm action
    }
}

Everything is fine and dandy until I try to switch timezones while app is running (after the setting was made). This is where the weird stuff begins. I can’t even describe what exactly is wrong other than that not matter what I do it doesn’t work right.

I guess what I am looking for is a general direction on how to do timezone-independent math in Java/Android either in Joda or standard APIs.

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

    As it turns out Jodatime does not handle timezone changes on Android. Restarting application helps, but that solution doesn’t work for a background service running all the time. I ended up rewriting code using Calendar/Date API even though it is ugly and painful.

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

Sidebar

Related Questions

I'm trying the basic jMonkey but I get this exception jun 27, 2012 9:25:08
I'm trying to access basic information from a FRIEND page via FQL: SELECT name,
I'm trying to get basic http authentication working on my Rails app. I'm offering
I am trying to understand basic OS concepts Want to know if my understanding
I'm trying to create basic search in my web app. Here's code of search
I am trying to do basic list operations with SML. I want to extract
I've been trying basic toString on the javascript date object, and after it wasn't
I was trying to perform basic authentication for Twitter from my Qt app. I
I'm trying to get basic localization working in a new Spring MVC app. I've
I was trying to convert basic Javascript function into PHP, and I saw that

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.