-
Notifications
You must be signed in to change notification settings - Fork 3
7. DateTime format
pdebacker edited this page Jun 6, 2013
·
2 revisions
Umbraco returns property values as string. Also date-time values. When having string properties representing date-time values and you want to convert these value into strong typed properties of type DateTime you can specify a DateTimeFormat attribute in which you specify the format to be used for the conversion. Example:
[DateTimeFormat("d/M/yyyy HH:mm")]
public DateTime DateTimeProperty { get; set; }
If the property is a generated property, you cannot simply add an extra attribute to that property because that would require you to change a generated class. In such a case you can specify a meta-data-class using System.ComponentModel.DataAnnotations. Example:
[MetadataType(typeof(ExampleModelMetaData))]
public partial class ExampleModel
{
}
public class ExampleModelMetaData
{
[DateTimeFormat("d/M/yyyy HH:mm")]
public DateTime DateTimeProperty { get; set; }
}