• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with millisecond date calculation  RSS feed

 
Malcolm Johnson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all...this is my first post.

I'm working on a program that is supposed to return a date that is 30 after an invoice date. When I run my program the date is not what I expect.

Here's the code from the class that gets and formats the due date:


Here's the code in the main class that calls the due date:

 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(30 * 24 * 60 * 60 * 1000) is a negative value.
Try (30L * 24 * 60 * 60 * 1000).
 
Malcolm Johnson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:(30 * 24 * 60 * 60 * 1000) is a negative value.
Try (30L * 24 * 60 * 60 * 1000).


That totally worked. I have no idea what the "L" accomplished though. I'll have to look it up! Thanks so much.
 
Malcolm Johnson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malcolm Johnson wrote:
Carey Brown wrote:(30 * 24 * 60 * 60 * 1000) is a negative value.
Try (30L * 24 * 60 * 60 * 1000).


That totally worked. I have no idea what the "L" accomplished though. I'll have to look it up! Thanks so much.


I checked my textbook and I get why this was a problem now. Int type doesn't accept a value that large. Thanks again!!
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should use a java.util.Calendar to perform date and time calculations.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better yet, use the Joda Time library which has a much better API than what's in standard Java for dealing with dates and times.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!