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

前端 未结 2 1372
萌比男神i
萌比男神i 2021-01-07 23:00

I\'m having a similar problem with FormatException being thrown. My code is simply:

void Orders_OnSubmit()
{
   DateTime CurrentTime = DateTime.Now;
   rtbAd         


        
2条回答
  •  梦谈多话
    2021-01-07 23:34

    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.

提交回复
热议问题