how to display date and time on the simulator

Hi all,

I am trying to display the date and time on the semulator.

How will I do that?

I have used the print function and it worked fine for me.

Seng Keat

Hi Seng,

You can use the display.newText() API for this, providing the same content as you give to the print statement. Here is the documentation:

http://docs.coronalabs.com/api/library/display/newText.html

Regards,

Brent Sorrentino

Hi Bren,

thanks you for your time to reply my question - now i am working on it some how if i got any error i will let u know,

Regards,

Seng Keat

Hi Bren,

pls help me to look at this code,

i got an error with it

local date = os.date("*t");

local showdate = display.newText(“date.year,date.month”, 0,0,native.systemFontBold,26);

local Date = display.newText(“hello world”, 0, 0, native.systemFontBold,46);

Date:setTextColor(255,255,255);

i want to display date on the simulator but can not,

can u tell me what’s wrong with it?\

Keat

Hi Keat,

By putting the value in quotes like this:

[lua]

“date.year,date.month”

[/lua]

You’re telling Corona to display that literal string, not the variable value. It should be like this:

[lua]

local date = os.date("*t");

local dy = date.year…", "…date.month;

local showdate = display.newText( dy, 0,0,native.systemFontBold,26 );

[/lua]

Brent

Hi Brent,

thanks you again for your quick respond - 

I just test it and it works out - 

Sincerly,

Keat

Hi Seng,

You can use the display.newText() API for this, providing the same content as you give to the print statement. Here is the documentation:

http://docs.coronalabs.com/api/library/display/newText.html

Regards,

Brent Sorrentino

Hi Bren,

thanks you for your time to reply my question - now i am working on it some how if i got any error i will let u know,

Regards,

Seng Keat

Hi Bren,

pls help me to look at this code,

i got an error with it

local date = os.date("*t");

local showdate = display.newText(“date.year,date.month”, 0,0,native.systemFontBold,26);

local Date = display.newText(“hello world”, 0, 0, native.systemFontBold,46);

Date:setTextColor(255,255,255);

i want to display date on the simulator but can not,

can u tell me what’s wrong with it?\

Keat

Hi Keat,

By putting the value in quotes like this:

[lua]

“date.year,date.month”

[/lua]

You’re telling Corona to display that literal string, not the variable value. It should be like this:

[lua]

local date = os.date("*t");

local dy = date.year…", "…date.month;

local showdate = display.newText( dy, 0,0,native.systemFontBold,26 );

[/lua]

Brent

Hi Brent,

thanks you again for your quick respond - 

I just test it and it works out - 

Sincerly,

Keat