How do you get the current time of day?

后端 未结 20 2618
长发绾君心
长发绾君心 2020-11-28 18:40

How do you get the current time (not date AND time)?

Example: 5:42:12 PM

20条回答
  •  悲哀的现实
    2020-11-28 19:18

    Current time with AM/PM designator:

    DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
    DateTime.Now.ToString("hh:mm:ss.fff tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
    

    Current time using 0-23 hour notation:

    DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)
    DateTime.Now.ToString("HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo)
    

提交回复
热议问题