Why does DateTime.Now.TimeOfDay.ToString("HH:mm:ss.ffffff") throw FormatException?

TimeOfDay is of type TimeSpan and it has different formatting options than DateTime. You also need to escape the colon (:)

 currentTime.TimeOfDay.ToString("hh\\:mm\\:ss\\.ffffff") 

Your sample tried to use the "HH" format which is defined for DateTime, but not for TimeSpan.


There's no need to explicitly access the Date and TimeOfDay properties of the DateTime instance. You can simplify your code like so:

rtbAdd(String.Format("Submitted on {0:MM/dd/yyyy} at {0:HH:mm:ss.ffffff}", DateTime.Now));