I'm trying to set a date field from a C# plugin. I have a string, and a custom date pattern. The date is always showing up in UTC time instead of EST.
I've tried using EST in my dateString and format. I've tried converting to UTC using DateTimeStyles.AdjustToUniversal and ToUniversalTime(). I've tried using DateTimeOffset instead of DateTime.
I know that I need to adjust my dateString before I set the field but not sure how.
The following code results in a time of 12:20 PM. Which makes sense because the current offset for UTC is -4
string dateString = "2019-12-30 4:20 PM";
string format = "yyyy-MM-dd h:mm tt";
try
{
DateTime myDate = DateTime.ParseExact(dateString, format, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None);
entity["field"] = myDate;
}
catch
{
throw new InvalidPluginExecutionException(dateString + " is an invalid date format");
}