PDA

View Full Version : [MX] Date object problem



Keith130
July 6th, 2003, 02:04 PM
I have the following AS on a frame :

stop();
myDate = new Date();
myTime = new Date();
_root.main.txtDate = myDate.getUTCDate()+" / "+myDate.getUTCMonth+" / "+myDate.getFullYear();
changeDate = setInterval(timeChange, 10);
function timeChange() {
_root.main.txtTime = myTime.getUTCHours()+":"+myTime.getUTCMinutes()+"."+myTime.getUTCSeconds();
}

It worksish and gives a date but the date is "6/6/2003" and the time is "18:3:4". AS you can see both the month and the hour are one short. I tired setting a variable as ther month and addin one to it but the output was NaN.


Oh and the setInterval doesnt change the time?? Any ideas about that?
Thanx in advance if you can help.

claudio
July 6th, 2003, 02:17 PM
Try replacing for dis code:
myDate = new Date();
myTime = new Date();
_root.main.txtDate = (myDate.getUTCDate()+" / "+(myDate.getUTCMonth()+1)+" / "+myDate.getFullYear());
changeDate = setInterval(timeChange, 10);
function timeChange() {
_root.main.txtTime = ((myTime.getUTCHours()+1)+":"+myTime.getUTCMinutes()+"."+myTime.getUTCSeconds());
}
stop();

I keep missing a +!!!

h88
July 6th, 2003, 02:23 PM
caludio solved your first issue, as of your second, try creating the date object everytime the function is called:


myDate = new Date();
_root.main.txtDate = (myDate.getUTCDate()+" / "+(myDate.getUTCMonth()+1)+" / "+myDate.getFullYear());
changeDate = setInterval(timeChange, 10);
function timeChange() {
_root.main.txtTime = ((new Date().getUTCHours()+1)+":"+new Date().getUTCMinutes()+"."+new Date().getUTCSeconds());
}
stop();

Keith130
July 7th, 2003, 06:10 AM
Thanx both of you, Now I see where I went wrong adding 1 to the month and hour. I nerver thought of declaring a new date everytime inside the function. I suppose it was like my Drag and Drop while easeing thing that I needed a function inside the button.onPress to update the targetX and targetY. Thanx again.

To see the calender in action go HERE (http://www33.brinkster.com/blowtorch/TGS/site1.html)

claudio
July 7th, 2003, 05:14 PM
No problem :)

Edenbridge
March 30th, 2006, 01:52 PM
ActionScript Code:



myDate = new Date();</p>
...
<p>function timeChange() {</p>
<p> _root.main.txtTime = ((new Date().getUTCHours()+1)+":"+new Date().getUTCMinutes()+"."+new Date().getUTCSeconds());</p>
<p>}</p>
<p>stop();








PinnedBot :) sorry that I ask you, but Isnt it the same if you use myDate.getUTCHours() or
new Date().getUTCHours()? I was thinking it is the same thing but as I see there is difference...Ihave also problem with digital world clock thats why Im asking.