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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:50:25+00:00 2026-06-09T02:50:25+00:00

Why javax.xml.datatype.Duration.getMinutes() always returns 0 although the duration is incremented? If you run the

  • 0

Why javax.xml.datatype.Duration.getMinutes() always returns 0 although the duration is incremented? If you run the code below longer than a minute you will see the output like this:

minutes: 0 , seconds: 61

I have never used this class before. Do I miss some basic knowledge about it?
Here is the code:

import java.util.Timer;
import java.util.TimerTask;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;

public class TestDuration {

    class MyTimerTask extends TimerTask {
        DatatypeFactory df;
        long delay;
        Duration duration;

        public MyTimerTask(DatatypeFactory df, long delay) {
            this.df = df;
            this.delay = delay;
            duration = df.newDuration(0);
        }

        @Override
        public void run() {
            duration = duration.add(df.newDuration(delay));
            System.out.println("minutes: " + duration.getMinutes() + " , seconds: " + duration.getSeconds());
        }
    }

    public static void main(String[] args) {
        Timer timer = new Timer();
        final long delay = 1 * 1000;
        DatatypeFactory df = null;

        try {
            df = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        MyTimerTask task = new TestDuration().new MyTimerTask(df, delay);
        timer.schedule(task, 0, delay);
    }
}
  • 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-09T02:50:27+00:00Added an answer on June 9, 2026 at 2:50 am

    This is by design it seems. Take a look at the JavaDoc for Duration.add():

    Computes a new duration whose value is this+rhs.

    For example,

    "1 day" + "-3 days" = "-2 days"
    "1 year" + "1 day" = "1 year and 1 day"
    "-(1 hour,50 minutes)" + "-20 minutes" = "-(1 hours,70 minutes)"
    "15 hours" + "-3 days" = "-(2 days,9 hours)"
    "1 year" + "-1 day" = IllegalStateException

    I’ve emboldened the line that matters here. Clearly this class is only concerned with correctly representing the interval, rather than worrying about what makes sense from a "human" perspective.

    Depending upon your use case, you can either continue to work with Duration, but understand that you will need to perform formatting calculations before displaying the value to a user, or you should move to a different class that does what you expect when you perform addition/subtraction. An example might be the Duration and Period classes from the Yoda Time project.

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

Sidebar

Related Questions

When I run this code: import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import
I have a property field in a class that is of type javax.xml.datatype.Duration .
I am looking for alternative SOAP ( javax.xml.soap ) implementation, other than Sun SAAJ
I am working on the following code: import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import
My code is not working: package com.foo.json; import javax.xml.bind.annotation.XmlRootElement; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; @XmlRootElement
I need to include/inherit javax.xml.datatype.XmlGregorianCalendar in my GWT module. I have a proxy gxt.xml
I'm looking for a simple method of converting between java.util.Date and javax.xml.datatype.XMLGregorianCalendar in both
Got an exception javax.xml.bind.UnmarshalException: unexpected element (uri:, local:ConnectorCommandType) trying to unmarshall xml, shown below:
I'm using the javax.xml.transform.Transformer class to perform some XSLT translations, like so: TransformerFactory factory
I wrote a handler (javax.xml.rpc.handler.Handler) for a SOAP web service that inspects header data.

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.