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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:47:54+00:00 2026-05-29T19:47:54+00:00

I need to format java XmlGregorianCalendar to yyMMdd string. My implementation: XMLGregorianCalendar date =

  • 0

I need to format java XmlGregorianCalendar to “yyMMdd” string.
My implementation:

XMLGregorianCalendar date = getDate(); //getting the date

if (date != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");

        LOG.debug("Parsing date...");
        LOG.debug("XML Date: " + date);
        LOG.debug("XML Date timezone: " + date.getTimezone());

        GregorianCalendar gc = date.toGregorianCalendar();

        LOG.debug("Gregorian calendar: " + gc.toString());
        LOG.debug("Gregorian calendar timezone id: " + gc.getTimeZone().getID());

        Date d = gc.getTime();

        LOG.debug("Date: " + d.toString());

        String formatted = sdf.format(d);

        LOG.debug("Formatted: " + formatted);
}

What I see in log:

Parsing date...
XML Date: 1943-04-15T00:00:00.000Z
XML Date timezone: 0
Gregorian calendar: java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+00:00",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1943,MONTH=3,WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=15,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]
Gregorian calendar timezone id: GMT+00:00
Date: Wed Apr 14 20:00:00 EDT 1943
Formatted: 430414

April, 15 was parsed as April, 14. What I’m doing wrong? When I should set timezone?

  • 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-29T19:47:58+00:00Added an answer on May 29, 2026 at 7:47 pm

    It was parsed as midnight on April 15th UTC. It was then formatted as 8pm on April 14th EDT, which is correct as EDT is four hours behind UTC.

    Note that Date.toString() always uses the local time zone – a Date object has no concept of which time zone it’s in.

    Your formatted value is also using the default time zone, as you haven’t specified a time zone. The calendar value (gc) is in UTC, but when you format it, it will apply the time zone from the formatter (as you format the Date value, which doesn’t have a time zone).

    It’s not clear what you were trying to achieve, but hopefully that will help. As an aside, I’d strongly recommend that you use Joda Time instead if you possibly can – it makes a lot of this much clearer.

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

Sidebar

Related Questions

I need to format my date (in Java) which is in String format. When
I need to change the date format using Java from dd/MM/yyyy to yyyy/MM/dd
I am using android.text.format.DateFormat.format(yyyy-MM-dd hh:mm:ss, new java.util.Date()) to get time & date. The problem
I need to automate getting the compilation date in a specific format into one
I have a date with String format 09-06-2011. I need to compare it with
I have a Date format in java that I need to save as a
How JAVA format date 4/06/2011 instead of 0 4/06/2011 ? I need to use
I need to convert a string time stamp value into Java Date object. The
In Java ME, I need to do a simple string substitution: String.format(This string contains
I need to print a formatted string containing scala.Long. java.lang.String.format() is incompatible with scala.Long

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.