Hi @sblb ,
The format of Created
is the default format of DateTimeOffset after be serialized, SO if you want to Convert DateTimeOffset to DateTime, You can use the following generic method to Convert DateTimeOffset to Date in class.
The following example defines a method named ConvertFromDateTimeOffset that converts DateTimeOffset values to DateTime values. Based on its offset, it determines whether the DateTimeOffset value is a UTC time, a local time, or some other time, and defines the returned date and time value's Kind property accordingly.
public static class Change
{
public static DateTime ConvertFromDateTimeOffset(DateTimeOffset dateTime)
{
if (dateTime.Offset.Equals(TimeSpan.Zero))
return dateTime.UtcDateTime;
else if (dateTime.Offset.Equals(TimeZoneInfo.Local.GetUtcOffset(dateTime.DateTime)))
return DateTime.SpecifyKind(dateTime.DateTime, DateTimeKind.Local);
else
return dateTime.DateTime;
}
}
After you submit the table, You can Convert DateTimeOffset to Date in your action, Then convert it into the time format you want and store it in the database.
[HttpPost]
public IActionResult Privacy(FilePath model)
{
//........
var dateTime = Change.ConvertFromDateTimeOffset(model.Created);
// your other code
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Xinran Shen