CAML输出从DateTime中删除时间



我正在使用Sharepoint Online列表创建一个博客卷,我希望DateTime只显示月份、日期和年份,而不是一周中的时间或日期。(目前正在制作"2018年7月11日星期三16:00:00 GMT-0500(中央夏令时("(

我当前的代码是:

$(function () {

ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");

});

function retrieveListItems() {

var clientContext = new SP.ClientContext();

var oList = clientContext.get_web().get_lists().getByTitle('News Archives');

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(
'<View><Query><Where><Leq><FieldRef Name="Publication_x0020_Date"  /><Value Type="DateTime"><Today /></Value></Lq></Where><OrderBy><FieldRef Name="Publication_x0020_Date" Ascending="False"/></OrderBy></Query><RowLimit>20</RowLimit></View>'

);

this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);

clientContext.executeQueryAsync(

Function.createDelegate(this, this.onQuerySucceeded),

Function.createDelegate(this, this.onQueryFailed)

);

}

function onQuerySucceeded(sender, args) {

var listItemInfo = '';

var listItemEnumerator = collListItem.getEnumerator();



while (listItemEnumerator.moveNext()) {

var oListItem = listItemEnumerator.get_current();        

listItemInfo += 
'<div class="newsitem">' +
'<h1 class="news-title"><a href="' + oListItem.get_item('Title0').get_url() + '">' + oListItem.get_item('Title') + '</a></h1>' +

'<p>' + oListItem.get_item('Author0') +  ', ' + oListItem.get_item('Publication_x0020_Date') + '</p>' +
oListItem.get_item('Summary_x0020__x002b__x0020_Medi') + 

'</div>';


}



$("#newsfeed").html(listItemInfo);

}
function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() +

'n' + args.get_stackTrace());

}

我希望调整这个部分

oListItem.get_item('Publication_x0020_Date')

提前感谢

您可以使用MicrosoftAjax.js来格式化日期时间字段,示例脚本。

<script src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript">
$(function () {
ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
});
function retrieveListItems() {
var clientContext = new SP.ClientContext();
var oList = clientContext.get_web().get_lists().getByTitle('News Archives');
var camlQuery = new SP.CamlQuery();
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var publicationDate = oListItem.get_item('Publication_x0020_Date');
var formatDate = publicationDate.format('MMM/dd/yyyy');
alert(formatDate);
}            
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'n' + args.get_stackTrace());
}
</script>

相关内容

  • 没有找到相关文章

最新更新