aspose file tools*
The moose likes Java in General and the fly likes GregorianCalendar  with negative time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "GregorianCalendar  with negative time" Watch "GregorianCalendar  with negative time" New topic
Author

GregorianCalendar with negative time

Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
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!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4546
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
The date based on calendar is about 2009/05/17, obviously after epoch, how come to negative time?
Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
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

Joined: May 03, 2008
Posts: 4546
    
    5

2009 BC is obviously before the epoch.
Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
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

Joined: May 17, 2004
Posts: 107
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
rk sharma
Ranch Hand

Joined: Jun 25, 2011
Posts: 50

Can you please explain some what briefly? what actually you want to know??


Regards,

RK
Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
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?

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GregorianCalendar with negative time