I’m receiving this error “String was not recognized as a valid DateTime” with the code below:
DateTimeOffSet dt=new DateTimeOffset(Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy hh:mm tt")));
It works in DEV environment but not in Production.
Could anyone please advice what’s wrong with the code above?
Thank you.
Convert.ToDateTime uses current culture information about DateTime format.
Try something like this: