Date Time (Unspecified)
Last updated
Was this helpful?
Was this helpful?
@Model.EventDateTime.Value@Model.Value<DateTime?>("eventDateTime"){
"date": "2025-01-01T00:00:00+00:00"
}using System.Text.Json.Serialization;
namespace UmbracoProject;
public class DateTimeUnspecified
{
/// <summary>
/// The date and time value, represented as a <see cref="DateTimeOffset"/> for storage compatibility.
/// </summary>
[JsonPropertyName("date")]
public DateTimeOffset Date { get; init; }
}DateTime dateTime = DateTime.Now; // Your existing DateTime value
DateTimeOffset dateTimeOffset = dateTime; // Explicit conversionvar value = new DateTimeUnspecified
{
Date = dateTimeOffset
};string jsonValue = _jsonSerializer.Serialize(value);IContent content = _contentService.GetById(contentKey) ?? throw new Exception("Content not found");
// Set the value of the property with alias 'eventDateTime'.
content.SetValue("eventDateTime", jsonValue);
// Save the change
_contentService.Save(content);