CAML 输出从 DateTime 中删除时间
CAML output remove time from DateTime
我正在使用 Sharepoint Online 列表创建博客滚动,我希望 DateTime 仅显示月、日和年,而不显示时间或星期几。 (目前生产 "Wed Jul 11 2018 16:00:00 GMT-0500 (Central Daylight Time)")
我当前的代码是:
$(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>
我正在使用 Sharepoint Online 列表创建博客滚动,我希望 DateTime 仅显示月、日和年,而不显示时间或星期几。 (目前生产 "Wed Jul 11 2018 16:00:00 GMT-0500 (Central Daylight Time)")
我当前的代码是:
$(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>