开发者

N2CMS formatting a date property with <n2:Display> tag

I have an EditableDate property and am displaying it in a WebForms page with <n2:Display> tag. The default output is something like 7/02/2011 12:00:00 AM however I would like to format the date like 7 February 2011. Have tried <n2:Display Format="{0:d MMM yyyy}"> however this just outputs {0:d MMM yyyy开发者_运维技巧}.


Not sure about this: could it be that you only need the formatting part?

<n2:Display Format="d MMM yyyy">


In your ContentItem, add a new property like "XDateString" as follow :

...
[EditableDate("Date", 50, ContainerName = Tabs.Content)]
public virtual DateTime? EventDate
{
      get { return (DateTime?)GetDetail("EventDate"); }
      set { SetDetail("EventDate", value); }
}

public virtual string EventDateString
{
     get
     {
         if (!EventDate.HasValue) return string.Empty;

         //Format here your Date
         return (EventDate.Value.ToString("d") + " " +
                 EventDate.Value.ToString("MMMM") + " " +
                 EventDate.Value.ToString("yyyy") 
                );
     }
}
...

Then in design page, add :

<n2:Display runat="server" PropertyName="EventDateString"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜