Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:27:49+00:00 2026-05-28T16:27:49+00:00

I have a project in mind where I would like to change the stylesheet

  • 0

I have a project in mind where I would like to change the stylesheet based on time of day. I had initially done this with php, but it grabbed the server’s time. Which was a less than ideal experience considering time zone differences.

I figure javascript may be the best bet to grab the users local time but I am not sure how I would write it. This is similar to what I had in mind, but I am thinking more every 3-6 hours change styles. Thanks in advance for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:27:50+00:00Added an answer on May 28, 2026 at 4:27 pm

    You could do something like this:

    $stylesheets = array(
        'foo.css',
        'bar.css',
        'baz.css',
        // ...
        'qux.css'
    );
    
    $numStylesheets = count($stylesheets);
    
    if (24 % $numStylesheets !== 0) {
        echo 'Number of stylesheets needs to be a factor of 24.';
        exit;
    }
    
    $hour = (int)date('H', $_SERVER['REQUEST_TIME']);
    $changeEveryXHours = 24 / $numStylesheets;
    $offset = floor($hour / $changeEveryXHours);
    $stylesheet = $stylesheets[$offset];
    
    echo '<link rel="stylesheet" href="', $stylesheet, '" />';
    

    It’s dynamic, based on the number of stylesheets you specify. Currently the number of stylesheets needs to be a factor of 24 (1, 2, 3, 4, 6, 8, 12, 24). You could get rid of this requirement by modifying the code to use minutes and seconds instead of just hours, but that’s too much math for me this morning. 🙂

    Edit: Here’s the same script in JS:

    var stylesheets = [
        'foo.css',
        'bar.css',
        'baz.css',
        // ...
        'qux.css'
    ];
    
    if (24 % stylesheets.length != 0) {
        alert('Number of stylesheets needs to be a factor of 24.');
        return false;
    }
    
    var now = new Date();
    var hour = now.getHours();
    var changeEveryXHours = 24 / stylesheets.length;
    var offset = Math.floor(hour / changeEveryXHours);
    var stylesheet = stylesheets[offset];
    
    // If you're using jQuery, I think it's something like this:
    $('<link>')
        .prop({
            rel: 'stylesheet',
            href: stylesheet
        })
        .appendTo($('head'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project in mind whose main selling point would be very good
I have a project in mind that will offer users their own domain, like
I have a project hosted on GitHub and I would like to work locally
We have an old project written using Managed C++ syntax. I would like to
I would like to work on an XYZ fantastic project I have in my
I have a project in mind that will require the majority of queries to
folks! I have project in cc.net and this project nay start by 3 ways
I have an interesting project in mind, and I have a question. You can
I have a project in mind, here's the pitch. When I come to a
I would like to run the following basic procedure within my Maven 3.0.4 project.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.