Updated time formatting function and it works better but not perfect.