/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System.Globalization/DateTimeFormatInfo/csharp/parse1.cs
46 строк
2 KB
Genevieve Warren
Extract remarks for System.Globalization* (#38912)
29 дек 2023, 20:03
Не верифицирован
29 дек 2023, 20:03
7f945f9
Код
Авторство
О чём код?
// <Snippet15> using System; using System.Globalization; public class ParseEx1 { public static void Main() { string[] dateStrings = { "08/18/2014", "01/02/2015" }; string[] cultureNames = { "en-US", "en-GB", "fr-FR", "fi-FI" }; foreach (var cultureName in cultureNames) { CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName); Console.WriteLine("Parsing strings using the {0} culture.", culture.Name); foreach (var dateStr in dateStrings) { try { Console.WriteLine(String.Format(culture, " '{0}' --> {1:D}", dateStr, DateTime.Parse(dateStr, culture))); } catch (FormatException) { Console.WriteLine(" Unable to parse '{0}'", dateStr); } } } } } // The example displays the following output: // Parsing strings using the en-US culture. // '08/18/2014' --> Monday, August 18, 2014 // '01/02/2015' --> Friday, January 02, 2015 // Parsing strings using the en-GB culture. // Unable to parse '08/18/2014' // '01/02/2015' --> 01 February 2015 // Parsing strings using the fr-FR culture. // Unable to parse '08/18/2014' // '01/02/2015' --> dimanche 1 février 2015 // Parsing strings using the fi-FI culture. // Unable to parse '08/18/2014' // '01/02/2015' --> 1. helmikuuta 2015 // </Snippet15>