DEV Community

Cover image for C# tips: DateTime formatting tip
Abdul
Abdul

Posted on

C# tips: DateTime formatting tip

If you want to do something like this:

2026/02/18 at 19:36
Enter fullscreen mode Exit fullscreen mode

You can do it like so:

time.ToString("yyyy/MM/dd 'at' HH:mm")
Enter fullscreen mode Exit fullscreen mode

You can even input any string you want in the formatting and it will not be changed or affected, as long as you put the single quotes around it.

time.ToString("yyyy/MM/dd 'just because 😄' HH:mm")

// Output
2026/02/18 just because 😄 19:36
Enter fullscreen mode Exit fullscreen mode

Thanks for tuning in!

Top comments (0)