SharePoint日期和时间时间:从REST访问时 [英] SharePoint Date & time : While accessing from REST

查看:123
本文介绍了SharePoint日期和时间时间:从REST访问时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想访问SharePoint Date&都使用REST API进行时间设置.我在Datetime字段上应用了过滤器,以比较我的日期和时间.但是我发现SharePoint正在为保存的项目返回UTC日期时间格式.

I wanted to access SharePoint Date & time both using REST API.. I have applied filter on Datetime field to compare my date&time. But I observe SharePoint is returning UTC datetime format for saved items. 

如何在不使用UTC日期时间格式的情况下应用过滤器?

How can I apply filter without UTC date-time format ?

我同时传递了日期和时间

I am passing Date and Time both 

"/_api/web/lists/GetByTitle('ListName')/Items?$filter=" + "((StartDate ge datetime'"+ valStartDate +"' and StartDate lt datetime'"+ valEndDate +"') or (EndDate gt datetime'"+ valStartDate +"' and EndDate le datetime'"+ valEndDate +"') or (datetime'"+ valStartDate +"' ge StartDate and datetime'"+ valStartDate +"' lt EndDate) or (datetime'"+ valEndDate +"' gt StartDate and datetime'"+ valEndDate +"' le EndDate) or (StartDate eq datetime'"+ valStartDate +"' and EndDate eq datetime'"+ valEndDate + "'))

推荐答案

作为一种解决方法,我们可以使用以下代码将本地时间转换为UTC日期时间,然后将数据传递到REST API中以过滤项目.

As a workaround, we can use the following code to convert the local time to UTC date time, then pass the data into REST API to filter items.

<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">


(document).ready(function(){ var date ="2017年9月18日晚上9:00"; var UTCDate = getUTCDate(date); console.log(UTCDate); }); 函数getUTCDate(date){ var UTCDate =";
(document).ready(function() { var date="9/18/2017 9:00 PM"; var UTCDate=getUTCDate(date); console.log(UTCDate); }); function getUTCDate(date){ var UTCDate="";


.ajax({ 网址:_spPageContextInfo.webAbsoluteUrl +``/_api/web/RegionalSettings/TimeZone/localTimeToUTC(@date)?@ date ='"+ date +"'', 方法:"GET", 标头:{"Accept":"application/json; odata = verbose}, 异步:假, 成功:功能(数据){ UTCDate = data.d.LocalTimeToUTC; }, 错误:函数(数据){ }, }); 返回UTCDate; } </script>
.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/RegionalSettings/TimeZone/localTimeToUTC(@date)?@date='"+date+"'", method: "GET", headers: { "Accept": "application/json; odata=verbose"}, async:false, success: function (data) { UTCDate=data.d.LocalTimeToUTC; }, error: function (data) { }, }); return UTCDate; } </script>

更多信息:

https://msdn.microsoft.com/zh-我们/library/office/jj246758.aspx?f=255&MSPPError=-2147217396

最好的问候,

丹尼斯


这篇关于SharePoint日期和时间时间:从REST访问时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆