;

PDA

Click to See Complete Forum and Search --> : Date and Time


Uwe S.
11-05-2007, 11:55 AM
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

blanius
11-05-2007, 01:13 PM
to get the current time and date you create a new date object Here's some code to play with


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

blanius
11-05-2007, 01:18 PM
Oh also for something simple if you don't mind the formating you can do this:

setclock=function(){
now=new Date()
txt1.text=now.toString()
}

setInterval(setclock,1000);

Uwe S.
11-06-2007, 06:05 AM
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!

blanius
11-06-2007, 12:02 PM
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.

blanius
11-06-2007, 12:32 PM
This tutorial is probably all you need:
http://www.senocular.com/flash/tutorials/countdown/

Uwe S.
11-07-2007, 04:00 AM
Hi Bret,

thank you for this information.
I will work today, read today, try today...

bye
Uwe

Uwe S.
11-07-2007, 12:07 PM
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


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....

blanius
11-08-2007, 08:59 AM
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

w.brants
11-08-2007, 09:36 AM
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 thismyDate = 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.

blanius
11-08-2007, 09:38 AM
Good point

Stoke Laurie
11-08-2007, 09:55 AM
<?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.

blanius
11-08-2007, 10:03 AM
Here's something I found and modified.

<!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

blanius
11-08-2007, 10:32 AM
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.

w.brants
11-08-2007, 11:14 AM
A way to get the server time and keep it running...

PHP file named servertime.php<? echo time() ; ?>

ActionScript codeServertimeUrl = '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.

Uwe S.
11-08-2007, 12:08 PM
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:


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.

w.brants
11-08-2007, 01:57 PM
You can also calculate things.
The example below creates three date objects.

currentDate ; the current moment
startDate; 17.00 today
endDate; 8.00 tomorrowcurrentDate = 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);

Uwe S.
11-09-2007, 05:07 AM
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:



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

<? echo time() ; ?>

then I made the swf File with the dynamic text txt1,
with this code
(edit Frame Action)

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:



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)

w.brants
11-09-2007, 07:06 AM
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<? 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 countdownServertimeUrl = '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';
}

}
}

Uwe S.
11-10-2007, 04:19 AM
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:

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/images/smilies/smile.gif
:)

w.brants
11-10-2007, 05:44 AM
You can change the ActionScript code to something like thisServertimeUrl = '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;
serverTimeDate = new Date(serverTime);
serverTimeM = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','S ep','Oct','Nov','Dec'][serverTimeDate.getUTCMonth()];
serverTimeD = serverTimeDate.getUTCDate();
serverTimeY = serverTimeDate.getUTCFullYear();

txt1.text = serverTimeM + ' ' + serverTimeD + ', ' + serverTimeY + '\n';

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';
}

}
}

w.brants
11-10-2007, 06:50 AM
I made a little mistake in my previous post. Here's the updated code that also displays the current timeServertimeUrl = '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;
serverTimeDate = new Date(serverTime);
serverTimeM = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','S ep','Oct','Nov','Dec'][serverTimeDate.getUTCMonth()];
serverTimeD = serverTimeDate.getUTCDate();
serverTimeY = serverTimeDate.getUTCFullYear();
serverTimeHrs = serverTimeDate.getUTCHours();
serverTimeMin = '0' + serverTimeDate.getUTCMinutes();
serverTimeMin = serverTimeMin.substr(-2);
serverTimeSec = '0' + serverTimeDate.getUTCSeconds();
serverTimeSec = serverTimeSec.substr(-2);

txt1.text = serverTimeM + ' ' + serverTimeD + ', ' + serverTimeY + ' ';
txt1.text += serverTimeHrs + ':' + serverTimeMin + ':' + serverTimeSec + '\n';

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.ceil(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';
}

}
}Example:
http://www.waterlijn.info/km/ServerTime/

Uwe S.
11-10-2007, 11:31 AM
Hi Wilbert,

your code is working fine! Everthing is finished and now this:


1. The servertime is one hour back!
I mean in germany it is 17:00
but the servertime is 16:00



and embeding is not correct!



When I embed the swf.file the servertime is not visible!
Although the servertime.php is in the same folder!



I got a problem, when I embed this swf file!

If I start the flash file directly, like
http:\\www........time.swf
it works fine with all the servertime!

If I embed this time.swf file in my Shop, it does not show the servertime, although I copied the servertime.php in the same folder where the swf file is!

Then I tried to embed the original Path:
I mean that path which is working...


<embed width="687" height="100" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www...../test/time.swf"></embed>



Im my folder test is the servertime.php and the time.swf
But it does not shows the servertime if I embed this file!


The website which embeded the time.swf file is a php site:


domain/index.php?cat=c14_city.html


I copied the servertime.php in the main folder without success!

Do you know the problem?

w.brants
11-10-2007, 12:02 PM
Try the base attribute. See this Adobe technote ...
http://www.adobe.com/go/tn_04157

Uwe S.
11-10-2007, 12:57 PM
Hi Wilbert,

thank you .... it is working now!
I changed the embeding code and copied the AC_FL_RunContent file
in the folder!
Embedding is now ok!

The servertime is one hour back!
I mean in germany it is 18:00
but the servertime shows 17:00

Do you know why?

THANK YOU SO MUCH for you patience with me!

Uwe

w.brants
11-10-2007, 01:21 PM
Did you use the php file with the date("Z") addition ?

If you did, I don't know why the servertime is different but the easiest fix in that case is a manual correction in the php file. First change <? echo time() + date("Z") ; ?> back to <? echo time(); ?> and see how many seconds the difference is with your current time. If for example the displayed time is two hours behind, simply correct the php file like this <? echo time() + 7200; ?>

Uwe S.
11-12-2007, 02:55 AM
Hi Wilbert,

Everthing works fine!


<? echo time() + 3600; ?>


You are a great programmer.
THANK YOU SOOOOO MUCH!

Bye
Uwe