当前位置: 首页 > 知识库问答 >
问题:

css取决于美国当前时间[重复]

景麒
2023-03-14

我有这个代码工作,但它读取他们的计算机的当前时间,我只想从美国获得小时数!不管你是否从其他国家访问它,css将根据美国时间使用。

 <script type="text/javascript">
datetoday = new Date(); // create new Date()
timenow = datetoday.getTime(); // grabbing the time, it is now
datetoday.setTime(timenow); // setting the time now to datetoday variable
hournow = datetoday.getHours();  //the hour it is
 <script type="text/javascript">
 $(document).ready(function () {
datetoday = new Date(); // create new Date()
timenow = datetoday.getTime(); // grabbing the time it is now
datetoday.setTime(timenow); // setting the time now to datetoday variable
hournow = datetoday.getHours();  //the hour it is


if (hournow >= 18)  // if it is after 6pm
    $('body').addClass('evening');
else if (hournow >= 12) // if it is after 12pm
    $('body').addClass('afternoon');
else if (hournow >= 6)  // if it is after 6am
    $('body').addClass('morning');
else if (hournow >= 0)  // if it is after midnight
    $('body').addClass('midnight');
});
 </script>

共有1个答案

阎建德
2023-03-14

使用Date.getTimezoneOffset()获取用户时区和UTC时间之间的差异。然后,如果您知道UTC时间和您需要的时区之间的差异:

var TIME_OFFSET = 5; //five hours difference to US East time.
var date = new Date();
date.setMinutes(date.getHours() + (date.getTimezoneOffset() / 60) - TIME_OFFSET);
var usHour = date.getHours();
 类似资料:
  • 问题内容: 获取当前UTC时间的功能是什么。我已经尝试使用System.getCurrentTime,但是我得到了设备的当前日期和时间。 谢谢 问题答案: 确实会提供自1970年1月1日UTC以来的毫秒数。您看到本地时间的原因可能是因为您在使用实例之前将其转换为字符串。您可以使用s 在任何时区将s 转换为s: 另请参阅此相关问题。

  • 问题内容: 我想要这样的当前时间戳: 1320917972 问题答案: 解决方案是:

  • 本文向大家介绍在Python中获取当前时间,包括了在Python中获取当前时间的使用技巧和注意事项,需要的朋友参考一下 若要将自纪元浮点值以来的秒数转换为时间元组,请将浮点值传递给一个函数(例如localtime),该函数返回一个具有全部九项有效的时间元组。 示例 输出结果 这将产生以下结果,可以将其格式化为任何其他可表示的形式-

  • rank ▲ ✰ vote url 38 508 92 515 url 在Python里获取当前时间 用什么方法或者模块获取当前时间? >>> import datetime >>> datetime.datetime.now() datetime(2009, 1, 6, 15, 8, 24, 78915) 如果只要时间: >>> datetime.datetime.time(datetime.

  • 我尝试使用Clock类来获取当前时间。 但问题是,它没有给我当前的时间,而是给出了: (当前时间-3小时) 所以我决定更精确地向程序指定我居住的城市。(贝鲁特) 还有,它给了我: