如何根据您的时区或当地时间确定显示的图像? [英] How can I determine what image shows up based on your time zone or local time?
问题描述
我无法访问php。这可能是w / jQuery吗?
这里是一个例子。
可以说,商家在上午11点开始营业,并在7点结束,希望现场聊天图像能够说'我们在线!',但是当他们关闭时,他们希望图像说'我们离线'。
这有帮助吗?如果有人有解决这个问题,请帮忙。谢谢。
以下是如何使用中央标准时间作为服务器的时区来补偿其他时区:
http://jsfiddle.net/pxfunc/AcFhg/2/
javascript / jQuery:
//翻译您的工作时间以UTC为例,此处使用中央标准时间(-0500 UTC)
// UTC中的开放时间为16,第二天的结束小时为0
var d = new Date(),
open = new Date(),
closed = new Date();
//为打开的
静态设置UTC日期open.setUTCHours(16); //开放时间为上午11:00 CST,即16:00 UTC
open.setUTCMinutes(0);
open.setUTCSeconds(0);
open.setUTCMilliseconds(0);
//静态设置关闭的日期
closed.setUTCDate(d.getUTCDate()+ 1); // UTC时间旋转回0,所以我们添加一天
closed.setUTCHours(0); //截止时间为晚上7:00 CST,即00:00 UTC(因此我们需要添加一天)
closed.setUTCMinutes(0);
closed.setUTCSeconds(0);
closed.setUTCMilliseconds(0);
//调试
console.log(user's date:+ d);
console.log(在用户的时区存储打开时间:+ open);
console.log(在用户时区存储关闭时间:+关闭);
console.log(d> open); //用户的时间大于开放时间
console.log(d
//测试商店是否打开?
if(d> open&& d< closed){
setOpenStatus(true);
}
else {
setOpenStatus(false);
函数setOpenStatus(isOpen){
$('#open')。toggle(isOpen);
$('#closed')。toggle(!isOpen);
}
注意:完全弥补各种夏时制变化在世界各地,但这对大多数情况都适用
I have no acess to php. Is this possible w/ jquery? Here is an example. lets say the business opens at 11:00am and closes at 7:00 and the would like for a live chat image to say 'we're online!' but when they're closed they want the image to say 'we're offline'. Does this help? If anyone has a solution to this please help. thanks.
Here's how to compensate for other timezones using Central Standard Time as the server's timezone:
http://jsfiddle.net/pxfunc/AcFhg/2/
javascript/jQuery:
// Translate your hours to UTC, example here is using Central Standard Time (-0500 UTC)
// Opening hour in UTC is 16, Closing hour is 0 the next day
var d = new Date(),
open = new Date(),
closed = new Date();
// Statically set UTC date for open
open.setUTCHours(16); // Open time at 11:00 am CST which is 16:00 UTC
open.setUTCMinutes(0);
open.setUTCSeconds(0);
open.setUTCMilliseconds(0);
// Statically Set UTC date for closing
closed.setUTCDate(d.getUTCDate()+1); // UTC time rotates back to 0 so we add a day
closed.setUTCHours(0); // Closing time at 7:00 pm CST which is 00:00 UTC (so we need to add a day)
closed.setUTCMinutes(0);
closed.setUTCSeconds(0);
closed.setUTCMilliseconds(0);
// Debugging
console.log("user's date:" + d);
console.log("store open time in user's timezone:" + open);
console.log("store close time in user's timezone:" + closed);
console.log(d > open); // user's time is greater than opening time
console.log(d < closed); // is user's time less than closing time (you don't have to go home...)
// Test for store open?
if (d > open && d < closed) {
setOpenStatus(true);
}
else {
setOpenStatus(false);
}
function setOpenStatus(isOpen) {
$('#open').toggle(isOpen);
$('#closed').toggle(!isOpen);
}
Note: it would be really difficult to fully compensate for the various daylight savings changes around the world but this will work for most cases
这篇关于如何根据您的时区或当地时间确定显示的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!