|
-
Date and Time
Hi,
some questions about date an time.
I must create a flash banner with the current time and the
current date.
Example:
Today it is ????????
the time now is ??????
Is that possible? I mean the banner should appear every 10 minutes in the website with this text? I do not know how...!
Thank you so much for help
Uwe
-
KoolMoves Moderator
to get the current time and date you create a new date object Here's some code to play with
Code:
dow=function(d,l){//returns Text Day of the week from number
week=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
sweek=new Array("Sun","Mon","Tues","Wed","Thur","Fri","Sat");
if (l=="short"){
return sweek[d];
}else{
return week[d];
}
}
moy=function(m){
month=new Array("January","Feburary","March","Apri","May","June","July","August","September","October","November","December");
return month[m];
}
now= new date()
h=now.getHours()
m=now.getMinutes()
s=now.getSeconds()
d=now.getDay()
y=now.getFullYear()
mm=now.getMonth()
dd=now.getDate()
txt1.text=h+":"+m+":"+s+" "+dow(d,"short")+", "+moy(mm)+"/"+dd+"/"+y
put a text field on the stage called txt1
This can be expanded quite a bit but I didn't have the time to do more than this
-
KoolMoves Moderator
Oh also for something simple if you don't mind the formating you can do this:
Code:
setclock=function(){
now=new Date()
txt1.text=now.toString()
}
setInterval(setclock,1000);
-
Hi,
thank you so much for your help. I will try it for my project.
Perhaps you have another professional advise!
Let me explain the Price-banner:
1. There is a Start Time in the morning 10:00 a clock
2. There is a End Time 08:00 next day in the morning!
The Message-Time is lets say 22 houres! (10:00 - 08:00 = 22 houres)
Is it possible to make a countdown of the time?
This price is valid for 22:00 hours
This price is valid for 21:59 hours
This price is valid for 21:58 hours...
If the clock time is 08:00 (next day...end of time)
then
this offer has ended!
-
KoolMoves Moderator
The Date Time math is harder than I thought. I'm looking into it. The Book Flash 8 ActionScript Bible has a DateTime Class that can do it. I'm trying to convert it right now. I have it typed in but it's not working as of yet.
-
KoolMoves Moderator
-
Hi Bret,
thank you for this information.
I will work today, read today, try today...
bye
Uwe
-
Found some interesting Code!
Hi Bret,
I found this code! Perhaps you know how to solve the problem!
1. Create a movie clip and inside this clip add a dynamic textfield. Then give this a variable name display (not an instance name) then attach the following code to the clip
Code:
onClipEvent (enterFrame) {
myDate = new Date();
endDate = new Date(2008, 7, 24); // the date to count down to note months are from 0 to 11
milliseconds = endDate-myDate; // milliseconds until the end date
if (milliseconds < 0) { // the date has passed
display = "You missed it";
} else {
days = (((milliseconds/1000)/60)/60)/24;
actualDays = Math.floor(days); // just use the integer part of the days
remain = days-actualDays;
hours = remain*24;
actualHours = Math.floor(hours);
remain = hours-actualHours;
minutes = remain*60;
actualMinutes = Math.floor(minutes);
remain = minutes-actualMinutes;
seconds = remain*60;
actualSeconds = Math.floor(seconds);
actualHours = (actualHours>9) ? actualHours : "0"+actualHours;
actualMinutes = (actualMinutes>9) ? actualMinutes : "0"+actualMinutes;
actualSeconds = (actualSeconds>9) ? actualSeconds : "0"+actualSeconds;
// do something to display the time remaining
display = actualDays+" days, "+actualHours+" hours, "+actualMinutes+" minutes, "+actualSeconds + " seconds";
}
}
My question to this code is: Can we change the Date fields?
Is it possible to create an automatic Day Field but every Day has a certain Start-Time and a certain End-Time! I mean the start Time is always 10:00 and the endTime is always 08:00 (22 houres)
Example:
Sunday, 7, November 2007 Start= 10:00 End = 08:00
Monday, 8, November 2007 Start= 10:00 End = 08:00
And then a textfield Countdown
6:43:33 to buy this Product
6:43:32 to buy this Product
00:00:00 END
I mean, the banner should automatic change the Date fields, and
Textfields should give the information 6:43:32 to buy this Product....
-
KoolMoves Moderator
I would imagine it's possible but I'm not sure how to approach it. I'm not that much of a programmer.
Your code does seem to work fine however be sure when you create a date to remember the month is a 0 based where 0=Jan and 11=December
Last edited by blanius; 11-08-2007 at 09:37 AM.
-
 Originally Posted by Uwe S.
Is it possible to create an automatic Day Field but every Day has a certain Start-Time and a certain End-Time!
It's possible to manipulate the time like this
Code:
myDate = new Date();
myDate.setHours(10);
myDate.setMinutes(0);
myDate.setSeconds(0);
but for a price offer it's useless because the time is based on the computer time. That way it's very easy to mess with your offer by changing the computer time. The only decent way in this case is to retrieve and use the time of the server or a time server but as far as I know you will need php or asp for that.
-
KoolMoves Moderator
-
That web bloke
<?php
$timestamp = time();
$datum = date("Y-m-d (D) H:i:s",$timestamp);
echo "Current date and local time on this server is $datum <br>\n";
?>
retrieves time and date from your server.
-
KoolMoves Moderator
Here's something I found and modified.
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
//FUNCTION FOR TIME LEFT
function time_left($integer)
{
$seconds=$integer;
if ($seconds/60 >=1)
{
$minutes=floor($seconds/60);
if ($minutes/60 >= 1)
{ # Hours
$hours=floor($minutes/60);
if ($hours/24 >= 1)
{ #days
$days=floor($hours/24);
if ($days/7 >=1)
{ #weeks
$weeks=floor($days/7);
if ($weeks>=2) $return="$weeks Weeks";
else $return="$weeks Week";
} #end of weeks
$days=$days-(floor($days/7))*7;
if ($weeks>=1 && $days >=1) $return="$return, ";
if ($days >=2) $return="$return $days days";
if ($days ==1) $return="$return $days day";
} #end of days
$hours=$hours-(floor($hours/24))*24;
if ($days>=1 && $hours >=1) $return="$return, ";
if ($hours >=2) $return="$return $hours hours";
if ($hours ==1) $return="$return $hours hour";
} #end of Hours
$minutes=$minutes-(floor($minutes/60))*60;
if ($hours>=1 && $minutes >=1) $return="$return, ";
if ($minutes >=2) $return="$return $minutes minutes";
if ($minutes ==1) $return="$return $minutes minute";
} #end of minutes
$seconds=$integer-(floor($integer/60))*60;
if ($minutes>=1 && $seconds >=1) $return="$return, ";
if ($seconds >=2) $return="$return $seconds seconds";
if ($seconds ==1) $return="$return $seconds second";
$return="$return.";
return $return;
}
/* Returns a string of the amount of time the integer (in seconds) refers
to.
$timeleft=time_left(86400);
$timeleft='1 day'.
Will not return anything higher than weeks. False if $integer=0 or fails.
*/
//int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )
$end= mktime ( 9,0,0,11,9,2007);
$now=time();
$left=$end-$now;
echo (date('l dS \of F Y h:i:s A',$end)."<BR>");
echo (date('l dS \of F Y h:i:s A',$now)."<BR>");
echo ($left."<BR>");
echo($timeleft=time_left($left));
?>
<body>
</body>
</html>
Not sure how to you can use it as you wouldn't want to call the server every second to keep it up to date. Maybe you could call the server to get the current and end times then run the Actionscript code on those dates
-
KoolMoves Moderator
Also you can use PHP to give you the server date in a format that you can use in Flash to create a date
<?php
echo($now=date("Y,n,j"));
?>
One problem is that the month will be 1 too many as PHP months are 1-12 and Flash is 0-11 but that's workable.
The thing I haven't figured out is to keep the clock running... i.e. seed the current time from the server's clock but to keep counting down. I suppose you could use setInterval to 1 millisecond and update the time that way.
-
A way to get the server time and keep it running...
PHP file named servertime.php
Code:
<? echo time() ; ?>
ActionScript code
Code:
ServertimeUrl = 'servertime.php?' + 1 * new Date();
addToTimer = 0;
lv = new LoadVars();
lv.onData = function(v) {
if (v != undefined) {
addToTimer = 1000 * v - getTimer();
}
}
lv.load(ServertimeUrl);
onEnterFrame = function(){
if (addToTimer) {
txt1.text = new Date(getTimer() + addToTimer);
}
}
A dynamic textfield named txt1 is required in this particular example.
-
Hi,
thank you all for your great help!
I tried to change the Data Fields from Wilbert!
It works so far! One Question to this code:
Code:
myDate = new Date(); // eg. now it is 17:00:00
endDate = new Date(); // the date to count down to note months are from 0 to 11
endDate.setHours(8); // This should be on the next day
endDate.setMinutes(30);
endDate.setSeconds(30);
milliseconds = endDate-myDate; // milliseconds until the end date
if (milliseconds < 0) { // the date has passed
display = "You missed it";
} else {
days = (((milliseconds/1000)/60)/60)/24;
actualDays = Math.floor(days); // just use the integer part of the days
remain = days-actualDays;
hours = remain*24;
actualHours = Math.floor(hours);
remain = hours-actualHours;
minutes = remain*60;
actualMinutes = Math.floor(minutes);
remain = minutes-actualMinutes;
seconds = remain*60;
actualSeconds = Math.floor(seconds);
actualHours = (actualHours>9) ? actualHours : "0"+actualHours;
actualMinutes = (actualMinutes>9) ? actualMinutes : "0"+actualMinutes;
actualSeconds = (actualSeconds>9) ? actualSeconds : "0"+actualSeconds;
// do something to display the time remaining
display = actualDays+" days, "+actualHours+" hours, "+actualMinutes+" minutes, "+actualSeconds + " seconds";
}
}
How can I get the time of the next Day! ...
I mean: StartTime is from 17:00 today
EndTime is 08:00:00 of the next Day!
I can change the houres to 23.59 and the countdown works.
-
You can also calculate things.
The example below creates three date objects.
currentDate ; the current moment
startDate; 17.00 today
endDate; 8.00 tomorrow
Code:
currentDate = new Date();
zeroHundredTodayUTC = 86400000 * Math.floor(currentDate / 86400000);
zeroHundredToday = zeroHundredTodayUTC + 60000 * currentDate.getTimeZoneOffset();
oneHour = 3600000;
startDate = new Date(zeroHundredToday + 17 * oneHour);
endDate = new Date(zeroHundredToday + 32 * oneHour);
-
Good morning Wilbert,
after houres of testing, I hope today will be a good day 1000 Questions...
My result: This code does not make a countdown between start and EndTime:
Code:
currentDate = new Date();
zeroHundredTodayUTC = 86400000 * Math.floor(currentDate / 86400000);
zeroHundredToday = zeroHundredTodayUTC + 60000 * currentDate.getTimeZoneOffset();
oneHour = 3600000;
startDate = new Date(zeroHundredToday + 10.00 * oneHour); // Die Uhrzeit von heute 10 Uhr
endDate = new Date(zeroHundredToday + 32.00 * oneHour); // Das Datum von Morgen
milliseconds = endDate-startDate; // milliseconds until the end date
if (milliseconds < 0) { // the date has passed
display = "Bitte keine Bestellungen mehr tätigen";
} else {
days = (((milliseconds/1000)/60)/60)/24;
actualDays = Math.floor(days); // just use the integer part of the days
remain = days-actualDays;
hours = remain*24;
actualHours = Math.floor(hours);
remain = hours-actualHours;
minutes = remain*60;
actualMinutes = Math.floor(minutes);
remain = minutes-actualMinutes;
seconds = remain*60;
actualSeconds = Math.floor(seconds);
actualHours = (actualHours>9) ? actualHours : "0"+actualHours;
actualMinutes = (actualMinutes>9) ? actualMinutes : "0"+actualMinutes;
actualSeconds = (actualSeconds>9) ? actualSeconds : "0"+actualSeconds;
// do something to display the time remaining
display = actualDays+" Tage, "+actualHours+" Stunden, "+actualMinutes+" Minuten, "+actualSeconds + " Sekunden";
}
}
If I change this Line to milliseconds = endDate-currentDate; then the countdown starts but not between start and endtime!
I tried the servertime without success!
I made the php file
Code:
<? echo time() ; ?>
then I made the swf File with the dynamic text txt1,
with this code
(edit Frame Action)
Code:
ServertimeUrl = 'servertime.php?' + 1 * new Date();
addToTimer = 0;
lv = new LoadVars();
lv.onData = function(v) {
if (v != undefined) {
addToTimer = 1000 * v - getTimer();
}
}
lv.load(ServertimeUrl);
onEnterFrame = function(){
if (addToTimer) {
txt1.text = new Date(getTimer() + addToTimer);
}
}
All files are in the same folder! If I start www......severtime.swf
the dynamic text is empty. I can not see the time.
How can I change this script with the correct servertime and date:
Code:
currentDate = new Date();
zeroHundredTodayUTC = 86400000 * Math.floor(currentDate / 86400000);
zeroHundredToday = zeroHundredTodayUTC + 60000 * currentDate.getTimeZoneOffset();
oneHour = 3600000;
startDate = new Date(zeroHundredToday + 10.00 * oneHour); // Die Uhrzeit von heute 10 Uhr
endDate = new Date(zeroHundredToday + 32.00 * oneHour); // Das Datum von Morgen
milliseconds = endDate-startDate; // milliseconds until the end date
if (milliseconds < 0) { // the date has passed
display = "Bitte keine Bestellungen mehr tätigen";
} else {
days = (((milliseconds/1000)/60)/60)/24;
actualDays = Math.floor(days); // just use the integer part of the days
remain = days-actualDays;
hours = remain*24;
actualHours = Math.floor(hours);
remain = hours-actualHours;
minutes = remain*60;
actualMinutes = Math.floor(minutes);
remain = minutes-actualMinutes;
seconds = remain*60;
actualSeconds = Math.floor(seconds);
actualHours = (actualHours>9) ? actualHours : "0"+actualHours;
actualMinutes = (actualMinutes>9) ? actualMinutes : "0"+actualMinutes;
actualSeconds = (actualSeconds>9) ? actualSeconds : "0"+actualSeconds;
// do something to display the time remaining
display = actualDays+" Tage, "+actualHours+" Stunden, "+actualMinutes+" Minuten, "+actualSeconds + " Sekunden";
}
}
....hmm Wilbert I am a bit confused with all of the parts...
How can I integrate the servertime in the movieclip Script, with a
correct countdown?
- Movie clip with the Code above (It works so far "without servertime")
- servertime.php (is on my Server)
- servertime Actionscript (...where can I integrate this code in the movieclip)
-
The previous php file I posted returned the GMT time. If you want it to return local time, use this PHP file named servertime.php instead
Code:
<? echo time() + date("Z") ; ?>
You can check if it works by viewing the file you uploaded to the server in your webbrowser. It should display a numeric value.
Modified ActionScript code to use the server time for a countdown
Code:
ServertimeUrl = 'servertime.php?' + 1 * new Date();
addToTimer = 0;
lv = new LoadVars();
lv.onData = function(v) {
if (v != undefined) {
addToTimer = 1000 * v - getTimer();
}
}
lv.load(ServertimeUrl);
oneHour = 3600000;
onEnterFrame = function() {
if (addToTimer) {
serverTime = getTimer() + addToTimer;
zeroHundred = 86400000 * Math.floor(serverTime / 86400000);
todayEightAM = zeroHundred + 8 * oneHour;
todayTenAM = zeroHundred + 10 * oneHour;
tomorrowEightAM = zeroHundred + 32 * oneHour;
if (serverTime < todayEightAM) {
remaining = todayEightAM - serverTime; // offer that started yesterday
} else if (serverTime > todayTenAM) {
remaining = tomorrowEightAM - serverTime; // offer that started today
} else {
remaining = 0; // no offer at this time
}
if (remaining){
remainingSeconds = Math.floor(remaining / 1000);
remainingMinutes = Math.floor(remainingSeconds / 60);
remainingHours = Math.floor(remainingMinutes / 60);
remainingSeconds -= remainingMinutes * 60;
remainingMinutes -= remainingHours * 60;
txt1.text = 'Countdown : ' + remainingHours + 'h ';
txt1.text += remainingMinutes + 'm ' + remainingSeconds + 's';
} else {
txt1.text = 'No offer at this time';
}
}
}
Last edited by w.brants; 11-09-2007 at 07:09 AM.
-
P E R F E C T!
Good morning Wilbert,
what can I say: You are ---- g r e a t ----! It is working perfekt.
ONE last question:
How can I show in a textfield the actual SERVER-Date with year and Day!
I placed that code to the end of file:
Code:
txt5.text = new Date(getTimer() + addToTimer);
it shows a number.
txt5.text = ServertimeUrl; too
Thank you sooo much.
Uwe
P.S.
Thank you all others too for help http://board.flashkit.com/board/imag...lies/smile.gif
Last edited by Uwe S.; 11-10-2007 at 05:02 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|