
In this article, find the C# Program to Get the Universal Time.
C# Program to Get the Universal Time
Here is an example of a C# program that gets the universal time and displays it on the console:
using System; class UniversalTime { static void Main(string[] args) { DateTime currentTime = DateTime.UtcNow; Console.WriteLine("The current universal time is: " + currentTime); } }
Here is an another example of a .NET program that converts an ASCII string to a Hexadecimal string:
using System; using System.Linq; class Program { static void Main(string[] args) { string input = "Hello World!"; string output = StringToHex(input); Console.WriteLine("Hexadecimal representation of '{0}': {1}", input, output); Console.ReadLine(); } static string StringToHex(string input) { return String.Concat(input.Select(c => ((int)c).ToString("X2"))); } }
This program uses the DateTime class’s UtcNow property to get the current universal time, and then uses the Console class’s WriteLine method to display the time on the console.
You can also format the output using ToString() method
Console.WriteLine("The current universal time is: " + currentTime.ToString("yyyy-MM-dd HH:mm:ss"));
This will give the output in Year-Month-Day Hour:Minutes:Seconds format.
– Article ends here –