• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple code verification using long variables

 
Peter McCarthy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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.
 
Robert Hill
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
K. Tsang
Bartender
Posts: 3403
13
Android Java
  • Mark post as helpful
  • send pies
  • 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?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic