1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Rep Power

    Question Anyone good at converting PHP into JavaScript?

    I have built a form with JavaScript that will alter the colors on the form in a day/night mode using a button and external JS.

    I have found a PHP code where it will express whether it is night or day based off of location and sunrise and sunset. I would like to incorporate it into my existing day/night mode in my form. But being it is entirely done in Java Script, I am finding it too hard to incorporate the PHP in.

    Was wondering if anyone would be able to help me by converting this PHP code into JavaScript?
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Rep Power
    Converting PHP to javascript is not always possible. In fact it usually isn't possible, since PHP is generally used for things where you need server access. But if all you want is the date and time, you can get it off the remote computer's clock. You ought to be able to figure something out using this...
    var time = new Date();
    alert(time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());
    getHours returns a number from 0 to 23 (military time). Just check as to your sunrise/sunset to see whether it is day or night, and you should be able to use your existing javascript code to change the colours to match the time.

IMN logo majestic logo threadwatch logo seochat tools logo