Search results
28 maj 2009 · Let's say you have a date with format yyMMdd. The fastest way to convert it that I found is: var d = new DateTime((s[0] - '0') * 10 + s[1] - '0' + 2000, (s[2] - '0') * 10 + s[3] - '0', (s[4] - '0') * 10 + s[5] - '0') Just, choose the indexes according to your date format of choice.
11 gru 2017 · Use DateTime.ParseExact() method. Converts the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.
4 paź 2022 · The DateTime.ParseExact method converts a string to a DateTime object if it conforms to one of the specified string patterns. When a string that isn't one of the forms specified is passed to this method, a FormatException is thrown.
13 maj 2021 · You can convert a string to a DateTime (parse) with one of these methods: DateTime.Parse() (or TryParse). Use this to parse a variety of standard formats (culture-specific or ISO-8601) DateTime.ParseExact() (or TryParseExact). Use this to parse from a specific format. I’ll show examples of using both methods for parsing various DateTime formats.
6 kwi 2024 · This post will discuss how to convert the specified string representation of a date and time format to its DateTime equivalent in C#. 1. Using DateTime.Parse() method. To convert a string representation of a date and time to the DateTime object, use the DateTime.Parse () method.
7 kwi 2023 · Whenever you have a string containing a date and time that may be invalid in formatting or that never occurred, you can use DateTime.TryParse. Tip It converts the string to a DateTime instance without raising an exception on errors.
25 mar 2015 · If you have a valid date string, you can use the Date.parse() method to convert it to milliseconds. Date.parse() returns the number of milliseconds between the date and January 1, 1970: