代码之家  ›  专栏  ›  技术社区  ›  Peter Jacoby

修改SharePoint中“上次修改”的日期格式:createdModifiedInfo

  •  1
  • Peter Jacoby  · 技术社区  · 15 年前

    我正在尝试使用该字段修改自定义模板中显示的日期格式。我要显示的是:

    此页上次修改时间为1月29日 2010年乔尔·斯波斯基

    (用户名链接到其配置文件)。

    我在这里找到了一些很好的例子 http://mindsharpblogs.com/aaron/archive/2008/02/08/4283.aspx 这帮助我建立了自定义模板。我查了一下 MSDN documentation . 但我不知道如何修改日期格式。

    是否有任何方法可以传递日期格式字符串,如“ 米姆伊依伊 “要用于渲染的FieldValue?

    这是我当前使用的代码,除了日期格式为29/01/2010 19:22,这不是用户友好的。

    <SharePoint:CreatedModifiedInfo ControlMode="Display" runat="server">
            <CustomTemplate>
                This page was last modified on
                <SharePoint:FieldValue FieldName="Modified" runat="server" ControlMode="Display" DisableInputFieldLabel="true"/>
                by
                <SharePoint:FormField FieldName="Author" runat="server" ControlMode="Display" DisableInputFieldLabel="true" />
            </CustomTemplate>
    </SharePoint:CreatedModifiedInfo>
    
    2 回复  |  直到 15 年前
        1
  •  0
  •   EG.    15 年前

    我想你可以直接调用那里的item字段值并格式化它。尝试下面的代码并将导入标记添加到标题。

    <%@ Import Namespace="Microsoft.SharePoint" %>
    ...
    <SharePoint:CreatedModifiedInfo ControlMode="Display" runat="server"> 
        <CustomTemplate> 
            This page was last modified on 
            <%=SPContext.Current.ListItem["Modified"]==null?"":((DateTime)SPContext.Current.ListItem["Modified"]).ToString("d MMM yyyy")%>
            by 
            <SharePoint:FormField FieldName="Author" runat="server" ControlMode="Display" DisableInputFieldLabel="true" /> 
        </CustomTemplate> 
    </SharePoint:CreatedModifiedInfo> 
    
        2
  •  0
  •   Peter Jacoby    15 年前

    我找到了一个稍有不同的解决办法。我对它不是百分之百的满意,但这很简单。这是基于我在这里读到的一个解决方案: http://panvega.wordpress.com/2009/03/16/masterpagepagelayout-format-date-field/

    您可以在“计算”类型的库中创建自定义列,并根据需要设置日期的格式。在我看来,这意味着:

    =TEXT(Modified,"d MMM yyyy")
    

    然后在页面布局中,我只引用了此字段,并且已经完成了格式设置:

    <SharePointWebControls:CalculatedField ID="CalculatedField" FieldName="Display Date" runat="server" />
    

    它不像我所寻找的那样优雅,主要是因为它需要在每个页面库中添加一个自定义列。但它只需要很少的代码。

    我仍然愿意寻求更好的解决方案。仅仅为了格式化一个日期就必须编写一个完整的Web控件似乎很奇怪,但这似乎是唯一更好的选择。