I was working on a functionality where we had to fetch list items from server using ECMA script (SharePoint 2010 Client Object Model) based on current datetime. The problem is that the datetime we were using to filter was that of the client machine which was different from that of server; the reason being, the client and the server were located in different timezones.

Please help me to find a way to get sharepoint server time using Javascript ClientObjectModel. The other restriction we have is that, we are not allowed to do any server side coding.

  • Do you try to use UTC date time format to solve your problem? – Alexander Mar 27 '12 at 7:27
  • Check regional settings on the site collection too - if they are setup correctly even though the server is in one time zone, dates/times will display correctly for other date/times – Russell Mar 27 '12 at 7:32
  • @Russell: I tried setting the regional settings to my local time zone, but unformtunately that didnt work out. – AbrahamJP Mar 28 '12 at 7:16

This question may help you find a solution: Getting date and time from SharePoint Server 2007 and throw it to Javascript variable

They suggest that you create a content editor web part on the page, put some JavaScript to set the date, and use inline server-side tags (if enabled) to print the server date/time.

  • The solution you had mentioned was quite a close shave, but as I am not allowed to alter the Web.Config it didnt work out for me. anyhow thanks for your suggestion – AbrahamJP Mar 28 '12 at 6:21
  • Ah ok - so inline server tags are disabled (I believe this is the default). – Russell Mar 28 '12 at 6:57

We have the same question. Answer here: JavaScript SP.CamlQuery() return DateTime fields with offset (in my case +11 hours)

But we have to use server insert in our web-part.

In you case in JS function dateTimeCalculateConsideringWebRegionalSettings you have to multiplied utcOffsetMinutes by -1


I can imagine some workaround - I think you can update an item in some list via client object model and then check the standard "Modified" datetime column for the updated item. It doesn't give you exactly current time but close to it. :)

<script type="text/javascript">
document.write("<p>" + Date() + "</p>");

By using the above JavaScript you can get the local time of your server.

  • The question is to get the server time, not the client time. – Brian Mar 27 '12 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.