Improved time formatting and handling