How to extract and display the hour from DateTime in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime now = DateTime.Now;

            string hour = now.ToString("h ");

            Console.WriteLine($"{hour}");
        }
    }
}


/*
run:
 
12

*/

 



answered Aug 14, 2018 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime now = DateTime.Now;

            string hour = now.ToString("HH ");

            Console.WriteLine($"{hour}");
        }
    }
}


/*
run:
  
16
 
*/

 



answered Aug 14, 2018 by avibootz

Related questions

1 answer 137 views
2 answers 201 views
1 answer 159 views
3 answers 229 views
1 answer 156 views
1 answer 164 views
1 answer 132 views
...