C# | Format Time

Asked

Viewed 207 times

-1

I need to format a date as follows:

Ex: 08:00 -> is 8h 08:30 -> is 8:30

You can do it right through DateTime.ToString();

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")
  • 1

    The toString accepts format definition - https://msdn.microsoft.com/pt-br/library/8kb3ddd4(v=vs.110). aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.