Skip to main content
Known Participant
March 25, 2019
Answered

trouble with simple date keeper

  • March 25, 2019
  • 5 replies
  • 702 views

I trouble with the day of week showing as a 2 digit number  it should show in this format 01/01/2019 but its showing 01/1/2019

any suggestions what I did wrong

import flash.utils.Timer;
import flash.events.TimerEvent;

var looper:Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopf);

function loopf(event:TimerEvent):void{
var time:Date = new Date();
var month:Number = time.getMonth()+1;
var day:Number = time.getDate();
var year:Number = time.getFullYear();

if (month < 10){
  date_txt.text = "0" + month + "/" + day + "/" + year;
} else{
  date_txt.text = month + "/" + day + "/" + year;
 
if (day < 10){
  date_txt.text = month + "/" + "0" + day +  "/" + year;
} else{
  date_txt.text = month + "/" + day + "/" + year;
 
  }

//date_txt.text = month + "/" + day + "/" + year;
}
}

This topic has been closed for replies.
Correct answer kdmemory

I have to correct myself. This is Actionscript 3, hence strict data typing:

import flash.utils.Timer;

import flash.events.TimerEvent;

var looper: Timer = new Timer(100);

looper.start();

looper.addEventListener(TimerEvent.TIMER, loopf);

function loopf(event: TimerEvent): void {

    var time: Date = new Date();

    var month: Number = time.getMonth() + 1;

    var day: Number = time.getDate();

    var year: Number = time.getFullYear();

    var monthStrg:String;

    var dayStrg:String;

    if (month < 10) {

        monthStrg = "0" + month + "/";

    } else {

        monthStrg = month + "/"

    }

    if (day < 10) {

        dayStrg = "0" + day + "/";

    } else {

        dayStrg = day + "/";

    }

   

    date_txt.text = monthStrg + dayStrg + year;

}

The previous one worked, but this is following the RULEZ.

Klaus

5 replies

Known Participant
March 26, 2019

I also have a question about a 05:00 minute time I have stop pause and restart all work fine on it, the problem is once I put into a game like second life only the person pressing start will actually see the time countdown any ideas how to fix that, I need to use it at place in game for auctions

kdmemory
Inspiring
March 26, 2019

"... once I put into a game like second life only the person pressing start will actually see the time countdown"

Are you talking about a multi-player scenario?

Known Participant
March 26, 2019

yes its a multiplayer rpg type game

this is what timer looks like   if want me to I will post its code

https://cldup.com/BwQcRTzCuN.swf

Known Participant
March 26, 2019

ok I got it now

thank you very much

Known Participant
March 26, 2019

I put your code in now it is giving a error

C:\Users\steel\Videos\Auction Timer\New folder (3)\timerClass.as, Line 1 5007: An ActionScript file must have at least one externally visible definition.

am I naming the class or should I just use actions for this

ty jeff

kdmemory
kdmemoryCorrect answer
Inspiring
March 26, 2019

I have to correct myself. This is Actionscript 3, hence strict data typing:

import flash.utils.Timer;

import flash.events.TimerEvent;

var looper: Timer = new Timer(100);

looper.start();

looper.addEventListener(TimerEvent.TIMER, loopf);

function loopf(event: TimerEvent): void {

    var time: Date = new Date();

    var month: Number = time.getMonth() + 1;

    var day: Number = time.getDate();

    var year: Number = time.getFullYear();

    var monthStrg:String;

    var dayStrg:String;

    if (month < 10) {

        monthStrg = "0" + month + "/";

    } else {

        monthStrg = month + "/"

    }

    if (day < 10) {

        dayStrg = "0" + day + "/";

    } else {

        dayStrg = day + "/";

    }

   

    date_txt.text = monthStrg + dayStrg + year;

}

The previous one worked, but this is following the RULEZ.

Klaus

kdmemory
Inspiring
March 26, 2019

HI daggerzEdge

Try it this way:

import flash.utils.Timer;

import flash.events.TimerEvent;

var looper: Timer = new Timer(100);

looper.start();

looper.addEventListener(TimerEvent.TIMER, loopf);

function loopf(event: TimerEvent): void {

    var time: Date = new Date();

    var month: Number = time.getMonth() + 1;

    var day: Number = time.getDate();

    var year: Number = time.getFullYear();

    var monthStrg, dayStrg;

    if (month < 10) {

        monthStrg = "0" + month + "/";

    } else {

        monthStrg = month + "/"

    }

    if (day < 10) {

        dayStrg = "0" + day + "/";

    } else {

        dayStrg = day + "/";

    }

   

    date_txt.text = monthStrg + dayStrg + year;

}

Klaus