GuruKulki GuruKulki - 7 months ago 37
Java Question

how to calculate a minutes from the TimeStamp in java?

I want to calculate the number of minutes from the TimeStamp. How to do that? for exmple

I have a TimeStamp value as 13/11/10 1:01 PM. I need to get that in minutes since the current time?

Hope I am clear


Assuming the value is in String.

  1. Parse that string using SimpleDateFormat's parse() method
  2. get the time in long from your Date object using getTime()
  3. Take a difference of System.currentTimeMillis() and the long received from getTime()
  4. Divide that by 1000 and then 60

Assuming the value is in Timestamp, skip step 1 and 2. And notice s in Timestamp is small.