/    Sign up×
Community /Pin to ProfileBookmark

Looking to create a global count-up Timer

Hi, i would like to use the following code to generate my time from there time zone, then have a code that uses that newly form time to generage a count-up timer from a time that i have imputed in the script manually. like the following code under it. I would appricate it so much if someone could help me with this problem.

[CODE]<script type=”text/javascript”>
<!–
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: William and Mari Bontrager :: http://willmaster.com/ */

<!– Copyright 1999, 2000 by William and Mari Bontrager.

// See complete instructions in the article “Easy Time
// Zone Offset Calculator” in WillMaster Possibilities
// issue # 46: http://willmaster.com/possibilities/archives/

here_offset = 300;
// The above number must be changed to the number of minutes
// difference between your time and UT during STANDARD TIME
// — not Daylight Savings Time. If you are in UT, (the
// same time zone as Greenwich, England), this number
// will be 0 (zero). If your time is later than UT (east
// of Greenwich, England), the number is negative.
// Otherwise, the number is positive.
// NOTE: To calculate the number automatically, go to
// http://willmaster.com/possibilities/demo/eztzoffset.html

DST_month_start = 0;
// If your geographical area observes daylight savings time,
// the above number represents the month the period begins.
// Otherwise, the number is 0 (zero).

DST_day_start = 0;
// If your geographical area observes daylight savings time,
// the above number represents day of the month the period
// begins. Otherwise, the number is 0 (zero).

DST_month_end = 0;
// If your geographical area observes daylight savings time,
// the above number represents the month the period ends.
// Otherwise, the number is 0 (zero).

DST_day_end = 0;
// If your geographical area observes daylight savings time,
// the above number represents day of the month the period
// ends. Otherwise, the number is 0 (zero).

clocktype = 12;
// The above number must be either 12 or 24. Use 12 if you
// want a 12-hour clock with “AM” or “PM” appended to the
// time. Use 24 if you want a 24-hour clock.
// NOTE: What you specify here is the default. You can change
// this value right before you use a function.

here_appt_weekday = 2;
// The day of the week in your time zone that you want
// calculated into your visitor’s time zone. Use a
// number 1-7: 1=Sunday 2=Monday 3=Tuesday
// 4=Wednesday 5=Thursday 6=Friday 7=Saturday
// NOTE: What you specify here is the default. You can change
// this value right before you use a function.

here_appt_hour = 10;
// The hour in your time zone that you want calculated into
// your visitor’s time zone. Use 12 for noon and 0 for midnight.
// NOTE: What you specify here is the default. You can change
// this value right before you use a function.

here_appt_minute = 27;
// The number of minutes after the hour in your time zone
// that you want calculated into your visitor’s time zone.
// NOTE: What you specify here is the default. You can change
// this value right before you use a function.

here_appt_ampm = ‘AM’;
// If the above appt_hour and appt_minute is before noon,
// use ‘AM’, otherwise use ‘PM’. If your clocktype
// variable (above) is 24, use ‘AM’;
// NOTE: What you specify here is the default. You can change
// this value right before you use a function.

// NOTE: The above appt_… variables must have values assigned
// to them whether or not you plan to calculate a specific
// time for your visitor’s time zone.

disp_dow = ‘yes’;
// Shall time displays include the day of the week (‘yes’ or ‘no’)?
// NOTE: What you specify here is the default. You can change
// it right before you use a function.

// No other customizations are required.

can_use_this = false;
if(parseInt(navigator.appVersion) >= 4) { can_use_this = true; }
vtime = new Date();
if(DST_month_start > 0) {
var b = false;
var m = vtime.getMonth();
var d = vtime.getDate();
DST_month_start–;
DST_month_end–;
if((m > DST_month_start) && (m < DST_month_end)) { b = true; }
else
{
if((m == DST_month_start) && (d >= DST_day_start)) { b = true; }
if((m == DST_month_end) && (d <= DST_day_end)) { b = true; }
}
if(b == true) { here_offset -= 60; }
}
Diff = vtime.getTimezoneOffset() – here_offset;
weekdays=new Array(“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”);
if(! weekdays) { can_use_this = 0; }
function get_future() {
if(can_use_this == false) { return ”; }
var apm = ‘AM’;
var rs = ”;
if((clocktype == 12) && (here_appt_ampm == ‘PM’)) { here_appt_hour += 12; }
b = new Date(vtime.getYear(),1,1,here_appt_hour,here_appt_minute,0);
var t = 0;
if(here_appt_weekday > 0)
{
var tt = here_appt_weekday – 1;
if(tt != b.getDay()) { t = tt – b.getDay(); }
}
if(t != 0) { b.setTime(Number(b) + (1000 * 60 * 60 * 24 * t)); }
b.setTime(Number(b) – (Diff * 60000));
var nowweekday = b.getDay();
var hr = b.getHours();
if(clocktype == 12)
{
if(hr > 11) { apm = ‘PM’; }
if(hr > 12) { hr -= 12; }
}
rs = hr + ‘:’;
if(b.getMinutes() < 10) { rs += ‘0’; }
rs += b.getMinutes();
if(clocktype == 12) { rs += ‘ ‘ + apm; }
if(here_appt_weekday > 0) { rs += ‘, ‘ + weekdays[b.getDay()]; }
return rs;
}
function get_current(s) {
if(can_use_this == false) { return ”; }
var apm = ‘AM’;
var rs = ”;
if((s == ‘here’) || (s == ‘Here’) || (s == ‘HERE’))
{
htime = new Date();
htime.setTime(Number(vtime) + (Diff * 60000));
var hr = htime.getHours();
if(clocktype == 12)
{
if(hr > 11) { apm = ‘PM’; }
if(hr > 12) { hr -= 12; }
}
rs = hr + ‘:’;
if(htime.getMinutes() < 10) { rs += ‘0’; }
rs += htime.getMinutes();
if(clocktype == 12) { rs += ‘ ‘ + apm; }
if((disp_dow == ‘yes’) || (disp_dow == ‘Yes’) || (disp_dow == ‘YES’))
{ rs += ‘, ‘ + weekdays[htime.getDay()]; }
}
else
{
var hr = vtime.getHours();
if(clocktype == 12)
{
if(hr > 11) { apm = ‘PM’; }
if(hr > 12) { hr -= 12; }
}
rs = hr + ‘:’;
if(vtime.getMinutes() < 10) { rs += ‘0’; }
rs += vtime.getMinutes();
if(clocktype == 12) { rs += ‘ ‘ + apm; }
if((disp_dow == ‘yes’) || (disp_dow == ‘Yes’) || (disp_dow == ‘YES’))
{ rs += ‘, ‘ + weekdays[vtime.getDay()]; }
}
return rs;
}
//–>
</script>

<!– Paste this code into the BODY section of your HTML document –>

Our current time »
<script language=”JavaScript”><!–
disp_dow = ‘no’;
document.write(get_current(‘here’));
//–>
</script>
<br>
Your current time »
<script language=”JavaScript”><!–
disp_dow = ‘no’;
document.write(get_current(‘visitor’));
//–>
</script>
<br>
Use this to compair your timezone.[/CODE]

[CODE]</style>

<script type=”text/javascript”>

function dcountup(startingdate, baseunit){
this.currentTime=new Date()
this.startingdate=new Date(startingdate)
this.timesup=false
this.baseunit=baseunit
this.start()
}

dcountup.prototype.oncountup=function(){} //default action for “oncountup”

dcountup.prototype.start=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
var timediff=(this.currentTime-this.startingdate)/1000 //difference btw target date and current date, in seconds
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit==”hours”){ //if base unit is hours, set “hourfield” to be topmost level
hourfield=dayfield*24+hourfield
dayfield=”n/a”
}
else if (this.baseunit==”minutes”){ //if base unit is minutes, set “minutefield” to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield=”n/a”
}
else if (this.baseunit==”seconds”){ //if base unit is seconds, set “secondfield” to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield=”n/a”
}
var result={days: dayfield, hours:hourfield, minutes:minutefield, seconds:secondfield}
this.oncountup(result)
setTimeout(function(){thisobj.start()}, 1000) //update results every second
}

</script>

<script type=”text/javascript”>

//SYNTAX: myvariable=new dcountup(past_date_and_time_string, “baseunit”)
var Gecounter=new dcountup(“March 8, 2010 13:18:15”, “days”)

Gecounter.oncountup=function(result){
//result is an object containing the current count up date/time, updated every second
//Available properties: result[“days”], result[“hours”], result[“minutes”], and result[“seconds”]
var mycountainer=document.getElementById(“cpcontainer”)
mycountainer.innerHTML=”Last Grand Exchange Update Detected: <br /><span class=’dcountstyle’>”+result[‘days’]+” <sup>days</sup> “+result[‘hours’]+” <sup>hours</sup> “+result[‘minutes’]+” <sup>minutes</sup> “+result[‘seconds’]+” <sup>seconds</sup></span>”
}

</script>[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Jkm01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...