
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Convert the value of the current DateTime object to UTC in C#
To convert the value of the current DateTime object to Coordinated Universal Time (UTC), the code is as follows −
Example
using System; public class Demo { public static void Main() { DateTime d = new DateTime(2019, 12, 11, 7, 11, 25); Console.WriteLine("Date = {0}", d); DateTime res = d.ToUniversalTime(); Console.WriteLine("String representation = {0}", res); } }
Output
This will produce the following output −
Date = 11/11/2019 7:11:25 AM String representation = 11/11/2019 7:11:25 AM
Example
Let us now see another example −
using System; public class Demo { public static void Main() { DateTime localDate, universalDate; String str = "11/11/2019 4:10:55"; localDate = DateTime.Parse(str); universalDate = localDate.ToUniversalTime(); Console.WriteLine("Local time = {0} ", localDate); Console.WriteLine("Universal time = {0} ", universalDate); } }
Output
This will produce the following output −
Local time = 11/11/2019 4:10:55 AM Universal time = 11/11/2019 4:10:55 AM
- Related Articles
- Convert the value of the current DateTime object to a Windows file time in C#
- How do I convert a datetime to a UTC timestamp in Python?
- C# DateTime to add days to the current date
- Convert the Current Time to a java.sql.Date Object
- How to convert timestamp string to datetime object in Python?
- Convert DateTime Value into String in MySQL?
- Inserting the current datetime in MongoDB?
- Pandas - Convert a Timestamp object to a native Python datetime object
- How to convert MySQL DATETIME value to JSON format in JavaScript?
- Java Program to convert LocalDate to java.util.Date in UTC
- MongoDB query to convert the field value and create datetime day of month during projection?
- C# DateTime Max Value
- How to convert C# DateTime to “YYYYMMDDHHMMSS” format?
- How to convert JavaScript datetime to MySQL datetime?
- Python Pandas - Construct a naive UTC datetime from a POSIX timestamp

Advertisements