0

I want to convert different date format to current date format

Example :

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("tr-TR");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("tr-TR");
string dateString = "16.03.2020 10:50:00"; //(I record the value) (now format dd.MM.yyyy HH:mm:ss)

//Change Culture (en-US)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

Datetime convertedDate = Convert.ToDatetime(dateString); //(now format dd/MM/yyyy HH:mm:ss)

error = String was not recognized as a valid DateTime

how can i solve ?

Sociopath
  • 13,068
  • 19
  • 47
  • 75
  • Checkout the documentation of `DateTimeFormatterBuilder` and `LocalDateTime.parse` and please use ISO formatting in your application so people can easily understand the dates. – Danny Varod Mar 16 '20 at 13:21
  • 1
    What language is this in? – Danny Varod Mar 16 '20 at 13:21
  • Is that C# or another .net-based language? Please tag your question accordingly since questions about hundreds og programming languages are asked here. It will also help attract those who know. And also mention the language in the text and/or the title. Thank you. I have voted to close in need of clarity and will be happy to remove my close vote after you have edited. – Ole V.V. Mar 17 '20 at 14:35

1 Answers1

0

I solved it this way

string dateString = "16.03.2020 10:55:10"; //Çağdaş SANCARBARLAZ
DateTime lastCheckDate = Convert.ToDateTime(dateString,
System.Globalization.CultureInfo.GetCultureInfo("tr-TR").DateTimeFormat);

Result :

Thank you everyone