我添加了一个当前工作的小提琴,我觉得它应该是正确的,但它似乎不起作用。
我所拥有的是显示/隐藏div的一些代码(在某些工作时间内基本上显示div) - 是否有一种简单的方法可以使用从UTC计算......以便显示/隐藏时间固定在某个时区。例如。美国东部时间下午6点而不是下午6点用户时间...这是我当前的代码:
var d = new Date();
var dayOfWeek = d.getDay();
var hour = d.getHours();
var mins = d.getMinutes();
var status = 'open';
if (dayOfWeek !== 6 && dayOfWeek !== 0 && hour >= 03 && hour < 15){
//if (hour=='10' && mins < '30'){
// status = 'closed';
// }else{
status = 'open';
// }
}else{
status = 'closed';
if (status=='open') {
$b('.orderby').show();
}else{
$b('.orderby').hide();
}
另外,我还有其他一些获得UTC差异的JavaScript:
function ShowTime() {
var now = new Date();
var diff = now.getTimezoneOffset() / 60; //the difference between local PC and UTC
diff = diff - 4; //the difference between UTC and EST
var hrs = 18-(now.getHours()+diff); //18 is the target hour
任何使节目/隐藏在特定时间内工作的方法吗?
答案 0 :(得分:1)
d.getDay()
个对象已经是UTC,当您使用d.getHours()
或d.getUTCDay()
时,会立即应用本地时区。
您只需使用d.getUTCHours()
,static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var myForm = new Form();
myForm.BackColor = System.Drawing.Color.Red;
// Do anything else to the form here in code
Application.Run(myForm);
}
等来阻止此