Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2006, 01:21 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default make date display go back a day

I have written this JS for a World Clock display
Code:
var el = 0;

function RefreshClock() 
{
    if(el) 
    {
        clearTimeout(el);
        el  = 0;
    }

    getTheDate(null);
    el = setTimeout("RefreshClock()", 111000);
}
function StartClock()
{
   el = setTimeout("RefreshClock()", 500);
}

function StopClock()
{
   if(el)
   {
      clearTimeout(el);
      el  = 0;
   }
}

function getTheDate(GMToffset)
{
    var orgdate=new Date();
    var year=orgdate.getYear();
    if (year < 1000)
    year+=1900;
    var day=orgdate.getDay();
    var month=orgdate.getMonth();
    var daym=orgdate.getDate();
    if (daym<10)
    daym="0"+daym;
    var dayArr=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var monthArr=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    var time = document.getElementById("time");
    var theDate = new Date();
    var frmtedDate = theDate.getHours();
    var GMTchange;

    if ((GMToffset!="0")&&(GMToffset!=null))
    {
        var oprtor = GMToffset.slice(0,1);
        if(GMToffset.length>2)
        {
            GMTchange = GMToffset.slice(1,3);        
        }
        else
        {
            GMTchange = GMToffset.slice(1,2);        
        }

        var preFrmtedDate = theDate.getHours();

        if(oprtor=="-")
        {
            frmtedDate = Number(parseFloat(preFrmtedDate)-parseFloat(GMTchange));
        }
        else if(oprtor=="+")
        {
            frmtedDate = Number(parseFloat(preFrmtedDate)+parseFloat(GMTchange));
        }
    }

    var theMinuten = theDate.getMinutes();

    if(parseFloat(frmtedDate)>24)
    {
        day = day+1;
        daym = daym+1;
        frmtedDate = parseFloat(frmtedDate)-24;
    }
    if(frmtedDate<10)
    {
        frmtedDate = "0"+frmtedDate;
        frmtedDate = parseFloat(frmtedDate);
    }    
    if(parseFloat(theMinuten)<10)
    {
        theMinuten = "0"+theMinuten;
        theMinuten = parseFloat(theMinuten);
    }
    time.innerHTML = frmtedDate;    
    time.innerHTML = time.innerHTML + "." + theMinuten + "&nbsp;" + dayArr[day] + ",&nbsp;" + monthArr[month] + "&nbsp;" + daym + ",&nbsp;" + year;
}
this is my table display...
Code:
<table width="750px"  border="0" cellpadding="0" cellspacing="2" >
  <tr>
    <td height="18" colspan="8" bgcolor="<%=headerCol%>"><table width="100%" border="1" bordercolor="<%=headerBrd%>" cellpadding="0" cellspacing="0">
        <tr>
          <td align="center" bordercolor="<%=headerCol%>" valign="top"><img border="0" src="/v2/asp/images/picco.gif"></td>
          <td bordercolor="<%=headerCol%>" valign="bottom" ><table align="right">
              <tr>
                <td id="location"><select name="cities" id="cities" class="selects" onchange="getTheDate(this.options[this.selectedIndex].value);">
                    <option value="0">London</option>
                    <option value="-5">New York</option>
                    <option value="+1">Paris</option>
                    <option value="-8">Los Angeles</option>
                    <option value="+9">Sydney</option>
                    <option value="+8">Singapore</option>
                    <option value="+13">Auckland</option>
                  </select>
                </td>
                <td id="time"></td>
              </tr>
            </table></td>
        </tr>
      </table>
 i was wondering if there is some code that you can see that will make it go back a day?? if you know what i mean

www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old March 7th, 2006, 01:35 AM
Authorized User
 
Join Date: Feb 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dimo414 Send a message via Yahoo to dimo414
Default

Perhaps I don't know what you mean, but cant you just subtract one from the variable 'day' and refresh the script??

 
Old March 16th, 2006, 01:42 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

yeah, that may be possible, I will try it at some point and get back to you.

www.crmpicco.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
subtracting 1 day from the current date Jeff C# 2 March 12th, 2009 01:16 AM
how to get the day from a given date pherms Classic ASP Basics 2 April 16th, 2004 05:38 PM
Asp day of month display karib Classic ASP Databases 10 April 5th, 2004 12:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.