How do you get the current time of day?

后端 未结 20 2520
长发绾君心
长发绾君心 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:37

    This will be better, Try This one

        DateTime.Now.ToShortTimeString();
    

    For this you don't need to specify the Format for the Time.

    0 讨论(0)
  • 2020-11-28 19:38

    Another option using String.Format()

    string.Format("{0:HH:mm:ss tt}", DateTime.Now)
    
    0 讨论(0)
  • 2020-11-28 19:41
    var CurDate= DateTime.Now;
    CurDate.Hour;
    CurDate.Minute;
    CurDate.Millisecond
    
    0 讨论(0)
  • 2020-11-28 19:42

    Here we go:

     DateTime time = DateTime.Now;
     Console.WriteLine(time.ToString("h:mm:ss tt"));
    
    0 讨论(0)
  • 2020-11-28 19:42

    To calculate the current datetime:

    DateTime theDate = DateTime.UtcNow;
    
    string custom = theDate.ToString("d");
    
    MessageBox.Show(custom);
    
    0 讨论(0)
  • 2020-11-28 19:42

    very simple DateTime.Now.ToString("hh:mm:ss tt")

    0 讨论(0)
提交回复
热议问题