UNPKG

spservices

Version:

Work with SharePoint's Web Services using jQuery

41 lines (34 loc) 1.3 kB
define([ 'jquery', '../utils/constants', '../core/SPServices.utils', //--------------------------- // We don't need local variables for these dependencies // because they are added to the jQuery namespace. '../core/SPServices.core' ], function ( $, constants, utils ) { "use strict"; // Convert a JavaScript date to the ISO 8601 format required by SharePoint to update list items $.fn.SPServices.SPConvertDateToISO = function (options) { var opt = $.extend({}, { dateToConvert: new Date(), // The JavaScript date we'd like to convert. If no date is passed, the function returns the current date/time dateOffset: "-05:00" // The time zone offset requested. Default is EST }, options); //Generate ISO 8601 date/time formatted string var s = ""; var d = opt.dateToConvert; s += d.getFullYear() + "-"; s += utils.pad(d.getMonth() + 1) + "-"; s += utils.pad(d.getDate()); s += "T" + utils.pad(d.getHours()) + ":"; s += utils.pad(d.getMinutes()) + ":"; s += utils.pad(d.getSeconds()) + "Z" + opt.dateOffset; //Return the ISO8601 date string return s; }; // End $.fn.SPServices.SPConvertDateToISO return $; });