Hour

I am trying to get the hour, using the following:

DateTime.Now.Hour

This works fine, but I need the format to be HH. So that 1:00 AM would return "01".

How would I go about accomplishing this

Thanks,
Russ



Answer this question

Hour

  • abhi_rock_star

    That worked perfect, and actually simplified something else for me.

    Thanks,
    Russ


  • Simple Samples

    look at the ToString() provider for the DateTime, which will allow you to customly return back the format you specify. In your case, try:

     

    string theHour = DateTime.Now.ToString("HH"); //24 hour format

    Does this help

    Here is a list of custom formats for your reference:

    http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx



  • Hour