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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:24:24+00:00 2026-05-13T12:24:24+00:00

I have following XML generated by serializing a boost::posix_time::ptime structure. I want to create

  • 0

I have following XML generated by serializing a boost::posix_time::ptime structure. I want to create a Java Date object with this XML.

<timeStamp class_id="0" tracking_level="0" version="0">
    <ptime_date class_id="1" tracking_level="0" version="0">
        <date>20100119</date>
    </ptime_date>
    <ptime_time_duration class_id="2" tracking_level="0" version="0">
        <time_duration_hours>11</time_duration_hours>
        <time_duration_minutes>53</time_duration_minutes>
        <time_duration_seconds>33</time_duration_seconds>
        <time_duration_fractional_seconds>0</time_duration_fractional_seconds>
    </ptime_time_duration>
</timeStamp>

Below is the Java code that is supposed to construct Date object by de-serializing this XML. Problem that I am facing is how to break the <date> tag into year/month/day sequence.

Integer date = timeStamp.getPtimeDate().getDate();
Integer hrs = timeStamp.getPtimeTimeDuration().getTimeDurationHours();
Integer mins = timeStamp.getPtimeTimeDuration().getTimeDurationMinutes();
Integer secs = timeStamp.getPtimeTimeDuration().getTimeDurationSeconds();

Calendar cal = Calendar.getInstance();
//TODO
//cal.set(year, month, day, hrs, mins, secs);
Date date = cal.getTime();

Any hints?

EDIT:

I am looking for some elegant solution that doesn’t require converting date to a string and then splitting it. That would be my last resort.

Thanks

  • 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-13T12:24:24+00:00Added an answer on May 13, 2026 at 12:24 pm

    As you don’t want to use a String (though I urge you to reconsider, after all that’s what it is and easier to parse too), I guess you can do regular old division to extract parts. i.e.

    int tmp = date; // unboxing
    int year = tmp / 10000;
    int month = (tmp % 10000) / 100;
    int day = tmp % 100;
    

    That’s not very elegant either.

    The best way to handle this would be to instruct whatever you’re using to deserialize to give you back a String for date instead of an Integer. Then you can just take the first four characters for your, next two for month and last two for day. SimpleDateFormat can do the heavy lifting here.

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

Sidebar

Related Questions

I have this SimpleXMLElement object with a XML setup similar to the following... $xml
I have following xml and I want to fetch the value of node which
I have following xml as a response to a service not i want to
I have the following XML :- <inventory> <item> <name_element> <!--some structure--> </name_element> <some_element1>val1</some_element1> <some_element2>val2</some_element2>
I have the following XML data which is generated by a webservice <?xml version=1.0
I have the following XML, which is generated by a 3rd-party library: <PhoneNumbers> <PhoneNumber
I have the following XML: http://pastebin.com/QiRK72BK which is generated in response to a REST
I have the following XML generated from various tables in my SQL SERVER database
I have generated a class from XSD. The following [System.Xml.Serialization.XmlElementAttribute(mailer, Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public itemOrderMailer[] mailer
I have to create xml after reading from a datatable, in C# application. This

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.