I need to check the difference between the time in database and system time.I am having both the times in yy:mm:dd hh:mm:ss format.please reply me how to do this .very urgent.I am getting both the time in string like
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss") ;
String currenttime = formatter.format (new Date()) ;
I am getting the output printed as
You have to obtain the to dates in Date instances. From there you get two milliseconds using Date.getTime. After that obtain the difference in milliseconds and with the difference create a new Date. Using SimpleDateFormat you cand print the difference.
So, as a rule of thumb, obtain milliseconds and do calculations in milliseconds. Don't parse or use Strings, is too complicated.