• 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

simple code verification using long variables

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
long now = System.currentTimeMillis();
long startValid = now;
long threeDays = 259200000;
long endValid = now + threeDays;

i have to alter some java code for a school project and i've never used java, only c++. does this code seem like it would work out OK? i'm not completely sure of the syntax in java. thanks.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By itself, the code you posted won't compile, of course.

But did you try to compile and run it?

why have 2 variables that store the same value(now and startValid)?
 
Peter McCarthy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Robert Hill:
By itself, the code you posted won't compile, of course.

But did you try to compile and run it?

why have 2 variables that store the same value(now and startValid)?



that's just a snippet from the whole code. everything compiles OK. I just wasn't sure if there was a certain way to initialize long values or add long values together that maybe I wasn't doing correctly, yet it was still able to compile.

as far as 2 variables storing the same value, those 2 lines were in the code given to me so i just didn't change them.

also, like i said, the code compiles and runs, but it's not doing what it should so i'm looking at it piece by piece to make sure i'm doing it all right.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

also, like i said, the code compiles and runs, but it's not doing what it should so i'm looking at it piece by piece to make sure i'm doing it all right.



Hi Peter,

Actually the code by itself alone compiles as is inside main() of course. Now as long as the threeDays variable value is the amount of milliseconds in 3 days then the endValid variable should be milliseconds 3 days from now. What output are you expecting?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code should be working as long as you don't consider daylight savings time.

If you do, java.util.Calendar would be better:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic