• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue with java.util.Calendar in java1.5 & above

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am facing issue while converting current date to Julian date in java 1.5 & above.

I am using the below piece of code which is working fine in java 1.4.

Is something wrong with logic or is it a know issue?



The output is showing a difference of 13 days. It is working fine if the below line is commented.



Any suggestions please why is this so?

Regards,

Srini
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags next time, instead of a different colour and size. I've modified your code parts for you to use them.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

seenu akula wrote: . . . I am facing issue while converting current date to Julian date in java 1.5 & above. . . .

You are using an awkward way to convert a date to a String. Try the String#format() method or one of the date format classes, eg SimpleDateFormat.

You also have format = "CCYYDDD"; on one line, followed closely by if ( . . . format.equals("yyddd")). Do you really think you will get true out of that?
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by 13 days out? What do you expect the date to be and what is displayed?
 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:What do you mean by 13 days out? What do you expect the date to be and what is displayed?



Hi Campbell Ritchie,

Thanks for the reply.

This particular logic is an existing logic from many years. I do not want to disturb the existing logic.


13 days out means

Java 1.4 is showing the result as:

Julian Date:2011007



where as Java 1.5 is showing the result as:


Julian Date:2010359


 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are getting 7th Jan 2011 when you expected 25th December 2010? And what was the original date you entered?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to have confused the "Julian date" with the "Julian calendar". There's no relationship between these two things (not even the "Julian" part of their names, which refer to two different Juliuses). So when you removed that line of code which fixed your problem, you removed a bug from your code.

And your code is far too complicated. You should be able to produce a Julian date representation of the current date in 3 lines of code, instead of the 15 that you used. (See Campbell's suggestion.) The more code you write, the more bugs you will have. So try to write less code.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, 25th December 2010 (Julian) and 7th January 2011 (Gregorian) are the same time. So, to all in Russia who still use the Julian Calendar, merry Christmas
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:You seem to have confused the "Julian date" with the "Julian calendar". . . .

When I looked on Wikipedia, I read that Julian dates are days and decimal fractions of days since 4713BC. So that output format is something different from what Wikipdeia describes as "Julian Day". Have you got a link to a Julian Date in the format 2011007 = today, please, Paul C.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Paul Clapham wrote:You seem to have confused the "Julian date" with the "Julian calendar". . . .

When I looked on Wikipedia, I read that Julian dates are days and decimal fractions of days since 4713BC. So that output format is something different from what Wikipdeia describes as "Julian Day". Have you got a link to a Julian Date in the format 2011007 = today, please, Paul C.



That's a good point. The "Julian day" you found is the one used by astronomers to provide a standard long-term timescale which is independent of popes mucking about with the calendar. The "Julian date" used frequently in computing is simply the number of the day in the year (so January 1 is represented by 1, February 15 is represented by 46, and so on). Here's a link if you want one: Julian Dates.
 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Actually, 25th December 2010 (Julian) and 7th January 2011 (Gregorian) are the same time. So, to all in Russia who still use the Julian Calendar, merry Christmas



I understood what you are saying. But I am trying to store todays date in julian date format in database.
This application runs in two servers out of which one uses java 1.4 and the other java 1.5. I am worried about the different values stored for the same date through different servers
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. So as we have been suggesting for quite some time now, stop using that bug-ridden code and use simple code which will work in all environments. Create a SimpleDateFormat using the YYDDD or CCYYDDD format, whichever it is you need. Use that to format the current date. That's all. No messing about with Calendar objects, no messing about with padding with zeroes if your string is too short, definitely no trying to use the Julian calendar. Just two or three lines of code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic