Calculate Date/Time Difference in Java considering AM/PM

前端 未结 6 554
陌清茗
陌清茗 2020-12-16 04:33

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

6条回答
  •  粉色の甜心
    2020-12-16 05:29

    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).

提交回复
热议问题