Formatting the Output
Format the output when printing date and time.
We'll cover the following...
We'll cover the following...
The problem
By default, when we print the DateTime
object, it has an inconvenient format:
Press + to interact
C#
using System;namespace DateTimeFormatting{class Program{static void Main(string[] args){var dateTime = new DateTime(2021, 12, 24, 17, 45, 23); // 12/24/2021 17:45:23Console.WriteLine(dateTime);}}}
This format may not be user-friendly. Fortunately, there are ways to change the output according to our needs.