This is a simple C# program that returns the current date and time in various formats. This program uses the DateTime.Now
property to get the current date and time. This C# code has separate function that takes a DateTime
object and a date/time format as parameters and returns the formatted date/time string. The Main function then passes various date/time formats to this function and prints the results:

Discover the mind behind the innovations – Elon Musk by Walter Isaacson, now on Audible. Dive into the life of a visionary shaping our future!
View on Amazon
In this code, the PrintFormattedDateTime
function takes a DateTime
object and a date/time format as parameters, and it prints the formatted date/time string using the GetFormattedDateTime
function. The GetFormattedDateTime
function takes the same parameters and returns the formatted date/time string using the ToString
method with the specified format.