How to convert decimal time to HH:MM:SS
Show older comments
I have a dataset and the dates are being read by matlab in decimal time. I want it instead in 24 hour time as in the 'HH:MM:SS' format. If anyone knows a way to do it, please let me know. I've attached the dataset to this question
Thanks.
Accepted Answer
More Answers (1)
format long g
T = now % so the current time in a decimal format
The integer part of that time represents days, and above. The fractional part represents the fractions of a day. So a fractinoal part that is at least 0.5 is a time at least noon.
datestr(T,'hh:mm:ss')
As you can see, the current time on the server is 2 PM, but the time shown shows a in 24 hour time format by default. So I'm not sure why you are asking. If you want it to show AM/PM, thus a 12 hour clock time, then you would do this:
datestr(T,'hh:mm:ss PM')
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!