在星期一至星期五的规定时间之间显示html内容 [英] Display html content between defined hours mon to friday
问题描述
我想知道是否有一个非常简单的解决方案来在欧洲时区中的某些小时之间以及仅在工作日内显示内容?
i was wondering if there is a quite simple solution to display content between certain hours and only during working days in a Europe timezone?
时间为每天上午9点至下午5点之间(周末除外),在这段时间之间应显示html内容. 如果可能的话,从5PM到9AM会有不同的html内容.
The hours will be everyday (except weekends) between 9AM and 5PM, between those times a html content should be shown. If possible a different html content from 5PM till 9AM.
推荐答案
简短的版本是使用new Date()
获取当前日期/时间,然后使用DOM操作适当地添加/删除该内容.如果要在页面加载之间更改内容,则可能还需要运行window.setInterval来不断更新内容.
The short version is that you use new Date()
to get the current date/time, and then you use DOM manipulation to add/remove that content as appropriate. If you want content to change in-between page loads, you'll probably also want a window.setInterval running to update things constantly.
您可能想看看Moment.js库(http://momentjs.com/),因为它具有许多使日期/时间的使用变得更容易的功能.
You might want to check out the Moment.js library (http://momentjs.com/), as it has a number of functions which make working with dates/times easier.
这是一个快速示例(不使用Moment),仅检查我们是否超过5分?":
Here's a quickie example (without using Moment) that just checks "are we past 5 or not?":
window.setInterval(function() {
if (new Date().getHours() > 17) { // if it's after 5pm (17:00 military time)
$('#someContent').hide();
} else {
$('#someContent').show();
}
}, 1000 * 60) // this will run every minute
希望借此,您可以弄清楚如何添加其他需要检查的内容.
With that hopefully you can figure out how to add the other needed if checks.
这篇关于在星期一至星期五的规定时间之间显示html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!