Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to parse a string with GMT into datetime in c#

I have this inputDateString: 15/03/2023 15:13:37 GMT and I want to convert it to datetime.

I am doing this: DateTime outputDate = DateTime.ParseExact(inputDateString, "MM/dd/yyyy:hhmmss \"GMT\"", CultureInfo.InvariantCulture);

I get this error: c# String '10/05/2023 18:19:27 GMT' was not recognized as a valid DateTime.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I convert this date string to a datetime?

>Solution :

your format date incorrect ,This code is correct,better but you must specify the timezone

DateTime outputDate = DateTime.ParseExact("15/03/2023 15:13:37 GMT", "dd/MM/yyyy HH:mm:ss GMT", CultureInfo.InvariantCulture);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading