• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Comparing dates...  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I subtract a date that is recent (a few weeks) from today's date, I get a negative number returned.



getTimeInMillis() returns a negative number if the date of entryDate is within the past few weeks.

Can anybody tell me why?
 
Sheriff
Posts: 21459
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should only return a negative value if the date is before 00:00:00 GMT on January 1st 1970. This date time is also called the epoch - see java.util.Calendar for more info. This point of time is represented as 0 in Java's calendars and dates (among others; PHP also uses it). Any time before that is always negative.

That still does not explain why a few weeks ago is negative. Can you tell us what values you are using when creating the GregorianCalendar?
 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks or replying!

Heres an example that returns a negative number...


then == a negative number.

Like I said though... it only does this if the past date is within a few weeks.
 
Sheriff
Posts: 23713
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that's not a "past date". It's March 23 of this year and we haven't got there yet.
 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:But that's not a "past date". It's March 23 of this year and we haven't got there yet.




Ahhh.... I see says the greenhorn! Thanks!
 
Rob Spoor
Sheriff
Posts: 21459
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is exactly why you can better use the Calendar constants like Calendar.FEBRUARY.
 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:This is exactly why you can better use the Calendar constants like Calendar.FEBRUARY.



The calendar is created with variables... The constants dont apply here. Thanks for the advice though!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!