Format the date time to string given the set format.