I want to calculate the difference between two date/time in java using Date and Calendar classes. The format that I have is \"2012-01-24 12:30:00 PM\".
I have implem
The problem is your date format: instead of yyyy-MM-dd HH:mm:ss a
use yyyy-MM-dd hh:mm:ss a
.
HH
will be the hour in day (0-23) whereas hh
will be the hour in AM/PM (1-12). Thus with your date format 02:30:00 will be parsed as just that instead of being converted to the PM version (which in hour of day would be 14:30:00).