• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

GregorianCalendar with negative time

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found an issue in code that GregorianCalendar with negative time and ERA as BC as below.
java.util.GregorianCalendar[time=-125520479618000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=0,YEAR=2009,MONTH=5,WEEK_OF_YEAR=25,WEEK_OF_MONTH=4,DAY_OF_MONTH=17,DAY_OF_YEAR=169,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=3,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=6,SECOND=22,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]

notice
time=-125520479618000,
ERA=0

It is only happened for the certain date, most other time and calendar are correct.


Good calenda

java.util.GregorianCalendar[time=1186393080000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2007,MONTH=7,WEEK_OF_YEAR=32,WEEK_OF_MONTH=2,DAY_OF_MONTH=6,DAY_OF_YEAR=218,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=38,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]


here
time=118639308000
ERA=1


Is there any case the GregorianCalendar could get the negative time ? Any suggestions are appreciated!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Jiang wrote:Is there any case the GregorianCalendar could get the negative time ? Any suggestions are appreciated!



The long value representing the time will be negative for any date/time before the epoch.
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The date based on calendar is about 2009/05/17, obviously after epoch, how come to negative time?
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the negative time is caused by ERA setting as 0 (BC) , I am wondering what reason could cause this issue? Thanks
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2009 BC is obviously before the epoch.
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some sample code as below,



and I get the result


JDBC Connect Example.
2009-06-17 16:06:22.893
new time in Millis from time is -125520450817107
Connected to the database
Disconnected from database



Looks like the DB result is OK like 2009-06-17 16:06:22.893, but the time is negative as -125520450817107.

How can we identify the DB data when it has negative time value?



 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I mean , for the data get from SQL, how could we know if the data is set as BC (or how to detect the wrong data with BC date) without converting it to Mill Seconds.

Thanks
 
Ranch Hand
Posts: 63
Spring Java Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please explain some what briefly? what actually you want to know??
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the data in DB looks correct when retrieving with SQL as 2009/06/07, but it shows as negative time after convert as mill seconds. what is caused the issue, and how can we detect the bad data with SQL?

 
Sheriff
Posts: 28321
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

Steve Jiang wrote:If the negative time is caused by ERA setting as 0 (BC) , I am wondering what reason could cause this issue? Thanks



The obvious reason would be that it's that way in the database.

How can we identify the DB data when it has negative time value?



That's a question about some unknown database, isn't it? Probably you know what the database is, but we don't. But just using basic SQL,
if you display a query which is sorted on the column containing that date, then the row containing that date should come at or near the
beginning.
 
Get me the mayor's office! I need to tell him about this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic