dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How do I display the time in a text box?

  1. #1
    Senior Member
    Join Date
    Mar 2003
    Location
    New Orleans
    Posts
    191

    How do I display the time in a text box?

    This should be simple.

    I have the following code:
    PHP Code:
    mydate = new Date();
    seconds mydate.getSeconds();
    minutes mydate.getMinutes();
    hours mydate.getHours();
    day mydate.getDay();
    date mydate.getDate();
    month mydate.getMonth();
    year mydate.getFullYear();

    if (
    day==0){
            
    day "Sunday"
    } else if (day==1){
            
    day "Monday"
    } else if (day==2){
            
    day "Tuesday"
    } else if (day==3){
            
    day "Wednesday"
    } else if (day==4){
            
    day "Thursday"
    } else if (day==5){
            
    day "Friday"
    } else if (day==6){
            
    day "Saturday"
    }

    if (
    month==0){
            
    month "January"
    } else if (month==1){
            
    month "February"
    } else if (month==2){
            
    month "March"
    } else if (month==3){
            
    month "April"
    } else if (month==4){
            
    month "May"
    } else if (month==5){
            
    month "June"
    } else if (month==6){
            
    month "July"
    } else if (month==7){
            
    month "August"
    } else if (month==8){
            
    month "September"
    } else if (month==9){
            
    month "October"
    } else if (month==10){
            
    month "November"
    } else if (month==11){
            
    month "December"
    }

    if (
    minutes<10) {
            
    minutes "0"+minutes;
    }
    if (
    seconds<10) {
            
    seconds "0"+seconds;
    }

    if (
    hours>12) {
            
    hours hours-12;
            
    ampm "PM";
    } else {
            
    ampm "AM";
    }
    if (
    hours == 0) {
            
    hours 12;
    }

    time = ((hours) + ":" + (minutes) + ":" + (seconds) + " " + (ampm)); 
    Now what do I need to do to display the time in a text box?
    thanks
    Last edited by lelales; 04-11-2005 at 05:55 PM.
    I'm only in it for the pleasure

  2. #2
    Senior Member
    Join Date
    Mar 2003
    Location
    New Orleans
    Posts
    191

    It was simple

    I made a dynamic textbox with the variable name as "time" and it worked.
    Last edited by lelales; 04-11-2005 at 05:58 PM.
    I'm only in it for the pleasure

  3. #3
    Senior Member
    Join Date
    Mar 2003
    Location
    New Orleans
    Posts
    191

    But the time doesn't update

    For example I tested the document and received the time in a dynamic text box, but the time doesn't update. It just shows the timne when the file was opened or tested.

    Any ideas on how to make time update?

    Do I need a onEnterFrame command at the start?
    I tried onEnterFrame but kept getting syntax errors.

    Any ideas?

    thanks
    Last edited by lelales; 04-11-2005 at 05:14 PM.
    I'm only in it for the pleasure

  4. #4
    Senior Member hum's Avatar
    Join Date
    Sep 2003
    Location
    CloudCuckooland
    Posts
    1,714
    Name your dynamic textbox....time
    then this on keyframe...
    code:
    onEnterFrame = function () {
    mydate = new Date();
    seconds = mydate.getSeconds();
    minutes = mydate.getMinutes();
    hours = mydate.getHours();
    day = mydate.getDay();
    date = mydate.getDate();
    month = mydate.getMonth();
    year = mydate.getFullYear();
    if (day == 0) {
    day = "Sunday";
    } else if (day == 1) {
    day = "Monday";
    } else if (day == 2) {
    day = "Tuesday";
    } else if (day == 3) {
    day = "Wednesday";
    } else if (day == 4) {
    day = "Thursday";
    } else if (day == 5) {
    day = "Friday";
    } else if (day == 6) {
    day = "Saturday";
    }
    if (month == 0) {
    month = "January";
    } else if (month == 1) {
    month = "February";
    } else if (month == 2) {
    month = "March";
    } else if (month == 3) {
    month = "April";
    } else if (month == 4) {
    month = "May";
    } else if (month == 5) {
    month = "June";
    } else if (month == 6) {
    month = "July";
    } else if (month == 7) {
    month = "August";
    } else if (month == 8) {
    month = "September";
    } else if (month == 9) {
    month = "October";
    } else if (month == 10) {
    month = "November";
    } else if (month == 11) {
    month = "December";
    }
    if (minutes<10) {
    minutes = "0"+minutes;
    }
    if (seconds<10) {
    seconds = "0"+seconds;
    }
    if (hours>12) {
    hours = hours-12;
    ampm = "PM";
    } else {
    ampm = "AM";
    }
    if (hours == 0) {
    hours = 12;
    }
    time = ((hours)+":"+(minutes)+":"+(seconds)+" "+(ampm));
    };


  5. #5
    Senior Member
    Join Date
    Mar 2003
    Location
    New Orleans
    Posts
    191

    problem solved

    No worries, jrd on actionscript set me up with some code.

    If anyone wants it, just ask and I'll post it for you.

    thanks
    I'm only in it for the pleasure

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center