string dateString = "11/12/2021 2:30 PM"; DateTime result; DateTime.TryParse(dateString, CultureInfo.InvariantCulture, DateTimeStyles.None, out result);
DateTime date = new DateTime(2021, 11, 12, 14, 30, 0); string result = date.ToString("MM/dd/yyyy hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);This code formats the DateTime object to a string in the format "MM/dd/yyyy hh:mm tt", using the invariant culture and assuming the time is in the UTC time zone. Package/Library: The DateTimeStyles enumeration is part of the System.Globalization namespace, which is included in the .NET Framework class library.