C # | Format Time

-1

I need to format a date as follows:

Ex: 08:00 - > It's 8am 08:30 - > It's 8:30 a.m.

You can do this directly through DateTime.ToString() ;

    
asked by anonymous 24.08.2017 / 21:48

1 answer

8

Simple:

DateTime.Parse("01/08/2017 08:30:00").ToString(@"HH\hmm")

If you want without 0 before 8, just change:

DateTime.Parse("01/08/2017 08:30:00").ToString(@"H\hmm")
    
24.08.2017 / 21:51