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