Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Extracting only time and suppressing date in C#

From DateTime format, we can get only time.

  1. using System;
  2.  
  3. namespace forgetCode
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. DateTime dt = DateTime.Now;
  11.  
  12. string Timeonly = dt.ToShortTimeString();
  13.  
  14. //Only hour and minute
  15.  
  16. Console.WriteLine(Timeonly);
  17. }
  18.  
  19. }
  20. }


Output:
16:04

..