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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:38:01+00:00 2026-06-10T08:38:01+00:00

i’m having a problem while converting Timestamp objects to joda’s LocalTime. See example below:

  • 0

i’m having a problem while converting Timestamp objects to joda’s LocalTime.

See example below:

public static void main(String[] args) {

    Timestamp t = Timestamp.valueOf("1111-11-11 00:00:00");
    System.out.println(t); //-- prints '1111-11-11 00:00:00.0'
    System.out.println(new LocalDate(t)); //-- prints '1111-11-17'

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(t);
    System.out.println(LocalDate.fromCalendarFields(calendar)); //-- prints '1111-11-11'
}

I could not determine why ‘new LocalDate(t)’ results in ‘1111-11-17’. Can anyone help me on that?

I notice this “problem” while using joda-time-hibernate to populate my bean’s property of type LocalDate.

  • 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-10T08:38:03+00:00Added an answer on June 10, 2026 at 8:38 am

    This indeed has to do with the different types of calendars. java.sql.Timestamp, like java.util.Date, don’t have any calendar information, as they are stored solely as a number, the number of milliseconds since 1970, with the implied assumption that there was a jump between October 4 and October 15 1582, when the Gregorian calendar was officially adopted, replacing the old Julian calendar. So, you can’t possibly have a Date (or Timestamp) object representing October 7, 1582. If you try to create such a date, you’ll automatically end up 10 days later. For example:

        Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("UTC"));
        c.set(1582, Calendar.OCTOBER, 7, 0, 0, 0);
        c.set(Calendar.MILLISECOND, 0);
        d = c.getTime();
        System.out.println("Date: " + d);
        // Prints:
        // Date: Sun Oct 17 00:00:00 GMT 1582
    

    In other words, Date objects have an implied Julian+Gregorian chronology, automatically switching between those two.

    JodaTime is a bit smarter, it supports several Chronologies, including a continuing Julian, a proleptic Gregorian, a mixed Julian+Gregorian, and a standard ISO Chronology which is almost identical to the Gregorian one. If you read the JavaDoc of the LocalDate.fromCalendarFields method, you’ll see that it mentions that:

    This factory method ignores the type of the calendar and always creates a LocalDate with ISO chronology.

    The mixed Julian+Gregorian chronology behaves like the implicit Java dates, with an automatic switch between the two different calendars. The pure chronologies assume that their calendar system is forever in use, so for example it assumes that the Gregorian calendar has been used since the start of time.

    Let’s see how each Chronology treats the 1111-11-11 date:

        Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("UTC"));
        c.set(1111, Calendar.NOVEMBER, 11, 0, 0, 0);
        c.set(Calendar.MILLISECOND, 0);
        Date d = c.getTime();
        System.out.println("Date: " + d + " (" + d.getTime() + " milliseconds)");
        System.out.println("ISO: " + new DateTime(d, ISOChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Julian+Gregorian: " + new DateTime(d, GJChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Julian: " + new DateTime(d, JulianChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Gregorian: " + new DateTime(d, GregorianChronology.getInstance(DateTimeZone.forID("UTC"))));
    

    Ends up as:

    Date: Sat Nov 11 00:00:00 GMT 1111 (-27079747200000 milliseconds)
    ISO: 1111-11-18T00:00:00.000Z
    Julian+Gregorian: 1111-11-11T00:00:00.000Z
    Julian: 1111-11-11T00:00:00.000Z
    Gregorian: 1111-11-18T00:00:00.000Z
    

    As you can see, the two modern chronologies (ISO and Gregorian) report the correct date if they would have been in use since from the start, while the two that use the Julian calendar report the date as it was known back then, although in hindsight we know it to be off by 7 days compared to the true equinox date.

    Let’s see what happened around the switch:

        c.set(1582, Calendar.OCTOBER, 15, 0, 0, 0);
        d = c.getTime();
        System.out.println("Date: " + d + " (" + d.getTime() + " milliseconds)");
        System.out.println("ISO: " + new DateTime(d, ISOChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Julian+Gregorian: " + new DateTime(d, GJChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Julian: " + new DateTime(d, JulianChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Gregorian: " + new DateTime(d, GregorianChronology.getInstance(DateTimeZone.forID("UTC"))));
    

    ends up as:

    Date: Fri Oct 15 00:00:00 GMT 1582 (-12219292800000 milliseconds)
    ISO: 1582-10-15T00:00:00.000Z
    Julian+Gregorian: 1582-10-15T00:00:00.000Z
    Julian: 1582-10-05T00:00:00.000Z
    Gregorian: 1582-10-15T00:00:00.000Z
    

    So the only one that’s left behind is the Julian calendar. That was a valid date in all the countries that didn’t accept the Gregorian calendar yet, which back then was a lot of countries. Greece made the switch in 1923…

    One millisecond before that, the date was:

        c.add(Calendar.MILLISECOND, -1);
        d = c.getTime();
        System.out.println("Date: " + d + " (" + d.getTime() + " milliseconds)");
        System.out.println("ISO: " + new DateTime(d, ISOChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Julian+Gregorian: " + new DateTime(d, GJChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Julian: " + new DateTime(d, JulianChronology.getInstance(DateTimeZone.forID("UTC"))));
        System.out.println("Gregorian: " + new DateTime(d, GregorianChronology.getInstance(DateTimeZone.forID("UTC"))));
    

    Meaning:

    Date: Thu Oct 04 23:59:59 GMT 1582 (-12219292800001 milliseconds)
    ISO: 1582-10-14T23:59:59.999Z
    Julian+Gregorian: 1582-10-04T23:59:59.999Z
    Julian: 1582-10-04T23:59:59.999Z
    Gregorian: 1582-10-14T23:59:59.999Z
    

    The ISO and Gregorian chronologies report a date that didn’t actually exist in the Gregorian calendar, since there was no Gregorian calendar before October 15, yet this date is valid in an extended, proleptic Gregorian calendar. It’s like finding a BCE date inscribed on a BCE monument… Nobody knew that they were before Christ before Christ was even born.

    So, the root of the problem is that a date string is ambiguous, since you don’t know in which calendar you’re measuring. Is the year 5772 a year in the future, or is it the current Hebrew year? Java assumes a mixed Julian+Gregorian calendar. JodaTime provides extensive support for different calendars, and by default it assumes the ISO8601 chronology. Your date is automatically converted from the Julian calendar in use in 1111 to the ISO chronology that we currently use. If you want your JodaTime-enhanced timestamps to use the same chronology as the java.sql.Timestamp class, then explicitly select the GJChronology when constructing JodaTime objects.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from

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.