• 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

problem with millisecond date calculation

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use a java.util.Calendar to perform date and time calculations.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Hold that thought. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic