SharePoint列表保存前一天的日期

时间:2016-08-31 15:21:22

标签: javascript sharepoint-2013

我需要使用javascript在sharepoint列表中保存日期,但在sharepoint中保存前一天的日期

Javascript" 18/08/2016"并列出sharepoint" 17/08/20106"

2 个答案:

答案 0 :(得分:0)

我在2013年的Sharepoint中进行了测试,似乎有效。

这是我的代码:

<script>
function getItemTypeForListName(listName) {
    return "SP.Data." + listName.charAt(0).toUpperCase() + listName.split(" ").join("").slice(1) + "ListItem";
};

function createNewItem(customerData, listName) {
    var strData = JSON.stringify(customerData);
    var urlListe =  "http://[URL_OF_YOUR_SP_SITE]/_api/web/lists/getbytitle('" + listName + "')/items";
    $.ajax({
        type: "POST",
        url: urlListe,
        dataType: "json",
        contentType: 'application/json;odata=verbose',
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        processData: false,
        data: strData,
        success: function (data) {
            $('#SaveResult').html('Success');
        },
        error: function (data) {
            $('#SaveResult').html('Error');
        }
    });
}
$(document).ready(function(){
    $('#SaveDateToList').on('click',function(){
        var fechaPa = "18/08/2016"; 
        var fechaPag = fechaPa.split("/")[1] +"/"+ fechaPa.split("/")[0] +"/"+ fechaPa.split("/")[2]; 
        fechaPago = new Date(fechaPag); 
        fechaPago = fechaPago.toISOString() 
        var customerData = { 
            __metadata:{
                type:getItemTypeForListName("TestList")
            }, 
            TestDate:fechaPago 
        }; 
        createNewItem(customerData, "TestList");
    });
});
</script>

<a id="SaveDateToList">Save</a>

<div id="SaveResult"></div>

答案 1 :(得分:0)

Sharepoint factors in Time Zones, and will alter dates if the originating time zone is different than the server time zone. Dates without a specified time default to midnight(00:00). If the server time zone is behind the originating time zone, this will cause the date to roll back a day