开发者

Where does .getHours in jQuery datepicker get its time from? And how to control it? Timezones

I need to dictate what time it is. It seems that .getHours uses the users system time. What if I need to set this to a certain timezone? I can't find anything in the documentation on setting the default timezone.

I have a delivery script for a site in Chicago, and currently if someone orders on the west coast they can inadvertently game开发者_如何学运维 the system and the 12 noon delivery cut off for next day delivery.

EDIT: So I found this:

$(document).ready(function(){
  var timezone = "Europe/Berlin";
  $.getJSON("http://json-time.appspot.com/time.json?tz="+timezone+"&callback=?",
    function(data){
      if (data.hour < 12) {
        alert ("Good morning in "+timezone);
      } else {
        alert ("Good afternoon in "+timezone);
      }
    })
});

from here: How can I obtain the local time in jQuery?

Not sure where to take this with the time validation though....


As JavaScript is client-side, it makes sense that it would get the data from the user's system.

If you want to manage the time, you'll have to (ultimately) do so server-side (which is the case for any user input, really). While you can provide feedback on the client, you should always validate inputs server-side to ensure the user isn't trying to get around any of your validation. Client-side validation is purely for convenience and user feedback.

You can start the user with a certain time by sending data from the server to populate the jQuery datepicker's time. This way, you'll at least start out with a certain time the pertains to the timezone you are interested in. Again, the user doesn't have to obey that as they control the client and, thus, could always game the system with out server-side checks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜