- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert.ToDateTime(String, IFormatProvider) Method in C#
The Convert.ToDateTime() method in C# converts the specified string representation of a number to an equivalent date and time, using the specified culture-specific formatting information.
Syntax
Following is the syntax −
public static DateTime ToDateTime (string val, IFormatProvider provider);
Above, value is a string that contains a date and time to convert, whereas the provider is an object that supplies culture-specific formatting information.
Example
Let us now see an example to implement the Convert.ToDateTime() method −
using System; using System.Globalization; public class Demo { public static void Main(){ CultureInfo cultures = new CultureInfo("en-US"); String val = "11/11/2019"; Console.WriteLine("Converted DateTime value..."); DateTime res = Convert.ToDateTime(val, cultures); Console.Write("{0}", res); } }
Output
This will produce the following output −
Converted DateTime value... 11/11/2019 12:00:00 AM
Advertisements