C# Program to get the Universal Time

«
»

This is a C# Program to get the universal time.

Problem Description

This C# Program gets the Universal Time.

Problem Solution

Here the universal time is calculated using the timezone function.

advertisement
Program/Source Code

Here is source code of the C# Program to get the Universal Time. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to get the Universal Time
 */
using System;
class Program
{
    static void Main()
    {
        TimeZone zone = TimeZone.CurrentTimeZone;
        DateTime univ = zone.ToUniversalTime(DateTime.Now);
        Console.WriteLine("Universal Time is {0}",univ);
        Console.Read();
    }
}
Program Explanation

This C# program is used to get the universal time. Here the universal time is calculated using the timezone function. The ToUniversalTime() method recognizes only the current adjustment rule when converting from local time to UTC. As a result, conversions for periods before the current adjustment rule came into effect may not accurately reflect the difference between local time and UTC.

advertisement
Runtime Test Cases
 
Universal Time is 10/22/2013 5:23:25 PM

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn