简体   繁体   中英

Switching between CultureInfo in C#

I am new to C# . I am trying to parse a csv file with Datatype.tryParse() .However The time stamp is changing across the csv file. Part of the file is DD/MM/YY and the other part is MM/DD/YY. How can I switch between the two formats? How to make the cultureInfo valid for the two formats ?

DateTime.TryParse(timeStamp, cultureInfo, DateTimeStyles.None, outputDate) ;

There is also an alternative method TryParseExact where you can define the format of the date you want to parse explicitely. Check the docs for more information

https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact?view=netcore-3.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM