如何在javascript或jquery中确定它是白天还是晚上? [英] How to determine if it is day or night in javascript or jquery?

查看:48
本文介绍了如何在javascript或jquery中确定它是白天还是晚上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据浏览器的时间将不同的CSS表格应用到我的网站。例如,如果是它的白昼时间,则显示day.css或night.css for night。

Im wanting to apply different CSS sheets to my site depending on the time of the browser. e.g if its day time, display day.css or night.css for night.

我可以用PHP执行此操作,但它基于服务器时间,而不是浏览器当地时间。

I can do this with PHP but it is based on the server time, not the browsers local time.

有没有办法在javascript中告诉时间?我可能会使用jQuery来简单地启动css。

Is there a way to tell the time in javascript? I'm probably going to use jQuery to simply initiate the css once its worked out.

推荐答案

var hr = (new Date()).getHours(); //get hours of the day in 24Hr format (0-23)

取决于您对日期的定义/晚上,执行你的魔法:)

Depending on your definition of day/night, perform your magic :)

PS:如果您的日/夜不是在确切时间开始,您可以尝试 getMinutes()

PS: If your day/night starts not at the exact hour, you can try getMinutes().

这篇关于如何在javascript或jquery中确定它是白天还是晚上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆