0
我有此代码工作,但它读取他们的计算机的当前时间,我只想从美国获得小时!不要紧,如果你从另一个国家访问它,CSS将按照美国时间使用。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>
美国有多个时区。你瞄准哪一个? –
相关:http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript – Douglas