I've been banging my head against my desk for a while now trying to use this REST endpoint in order to convert local time to UTC time.
The specific url I'm using is this:
http://<sitecollection>/<site>/_api/web/RegionalSettings/TimeZone/localTimeToUTC(date)
What I can't seem to figure out is how to pass a date and time to it without having it throw this error in my face:
A potentially dangerous Request.Path value was detected from the client (:).
Or claim that it cannot parse the date and time.
I simply cannot find any documentation that explains how I should encode the date and time to avoid the issue. The only answers seems to be to disable the security handler that throws the error, but I don't want to potentially compromise the system simply so that it will receive my date. This is part of the REST api so there must be some other way to encode the date and time that will allow me to use the endpoint right?
These are some of the urls I've tried and the error they return:
//Potentially dangerous (:)
/_api/Web/RegionalSettings/TimeZone/localTimeToUTC("2015-11-16T14:54:06.802Z")
/_api/Web/RegionalSettings/TimeZone/localTimeToUTC("2015-11-16T14%3A54%3A06.802Z")
//InvalidClientQueryExpression
/_api/Web/RegionalSettings/TimeZone/localTimeToUTC("2015-11-16T145406802Z")
/_api/Web/RegionalSettings/TimeZone/localTimeToUTC("2015-11-16T145406")
/_api/Web/RegionalSettings/TimeZone/localTimeToUTC("2015-11-16")
Edit:
For those looking for a way to do this with CSOM/JSOM, here is the way I solved it.
var date = "2015-11-17 16:00:00",
ctx = SP.ClientContext.get_current(),
regionalSettings = ctx.get_web().get_regionalSettings(),
timeZone = regionalSettings.get_timeZone(),
utcTimeResult = timeZone.localTimeToUTC(date);
ctx.load(regionalSettings); //Note that regional settings is the object you need to load
ctx.executeQueryAsync(function(){
var utcTime = utcTimeResult.get_value(); //Proper Date object with timezone offset
});