The time I get from the server is like Jul 27, 2011 8:35:29 AM
.
I want to convert it to yyyy-MM-dd HH:mm:ss
.
I also want the converted time to be in 24 hour format. Can any one give solution to this problem. The output I want to get is like 2011-07-27 08:35:29
For example if the time in 12 hour clock is 11:00 PM, then the time in 24 hour clock is 11:00 + 12:00 = 23:00 hours.
strptime() function to convert the string to a datetime object, and then using the string method strftime() to output the time in 24-hour format. The format code for 24-hour time is %H:%M whereas the format for 12-hour time is %I:%M with %p appended if the time contains AM/PM.
H vs h is difference between 24 hour vs 12 hour format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With