New Posts  All Forums:Forum Nav:

Java Timestamp Help

post #1 of 3
Thread Starter 
The language I'm using in is Java.

I would like to get how many minutes have passed since a timestamp was saved (in a rounded integer preferrably). Assume I already have the timestamp saved.

Thanks!
Edited by Lyoko - 7/6/08 at 3:33pm
post #2 of 3
Assume start is the value returned from a previous call to System.currentTimeMillis()

Code:
public int minutesElapsed(long start){
 long diff = System.currentTimeMillis() - start;
 return (int)((diff)/(1000*60));
}
That will truncate rather than round. I would suggest using a double to keep the fractional portion.

Note that if you multiply by .001 before storing you lose the decimal places and are left with seconds rather than milliseconds
Edited by rabidgnome229 - 7/5/08 at 9:27pm
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #3 of 3
Thread Starter 
Thanks a bunch once again! I'm not going to do the conversion since it looks like I'm not using UNIX timestamp. See you later
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming