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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:57:43+00:00 2026-06-17T10:57:43+00:00

I am getting a Date object, which i need to convert to XMLGregorian Calendar

  • 0

I am getting a Date object, which i need to convert to XMLGregorian Calendar specific format

I tried below ways

String formattedDate = sdf.format(categoryData.getBulkCollectionTime()); //yyyy-MM-dd HH:mm:ss
XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(formattedDate);
dataListType.setTimestamp(xmlCal);

I am getting an exception, for sure I am doing wrong here. But I want to format the Date object into specified format, which is done by sdf.format perfectly.

But how do I create the XMLGregorianCalendar object for the same (from formattedDate)?

  • 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-17T10:57:44+00:00Added an answer on June 17, 2026 at 10:57 am

    You can do it by the date object itself:

    String formattedDate = sdf.format(categoryData.getBulkCollectionTime()); //yyyy-MM-dd HH:mm:ss
    convertStringToXmlGregorian(formattedDate);
    
    
    public XMLGregorianCalendar convertStringToXmlGregorian(String dateString)
    {
          try {
                Date date = sdf.parse(dateString);
                GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
                gc.setTime(date);
                return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
            } catch (ParseException e) {
                // Optimize exception handling
                System.out.print(e.getMessage());
                return null;
            } 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an NSDate object from an old date which i am getting from
I am getting the date string from the server as 2012-06-21 18:13:33 -04:00 What
I am getting an error in converting string to date in C#. The error
I'm getting an InstantiationException when trying to map Date -> Calendar. Simple test follows:
I'm having trouble getting a field which is in an object which is inside
Hi I have a user input form which takes date in 2011-05-12 format. I
I'm looking for an JavaScript algorithm to convert local calendar date-times into UTC milliseconds
I have a date picker for text field which puts in format of 5-MAY-2011
I'm getting a date from a string, parsing it to get the day, month
I have CalendarControl.js, which on selecting date gives me date in format 14-Aug-2012.But I

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.