简体   繁体   中英

Adobe Flash builder - Flex - Android - How to get time and date in a label?

I'm a newbie to Flex and I'd like someone to help me out with this. I want to add 2 label with its text being set as Date and Time. The 2 labels would display the current date and current time. I have surfed a lot on the internet but I couldn't find anything! Could someone be really kind and help me out with this? I'd greatly appreciate your help! Thanks, osama

Something like this will work in its simplest form:

<s:Label id="dateLabel" text="{(new Date()).toDateString()}"/>
<s:Label id="timeLabel" text="{(new Date()).toTimeString()}"/>

This will, in essence, create a new date object which represents the current date and time. Then the toDateString() or toTimeString() methods will be executed; and the value will be displayed in the label.

If you have a date object through some other means, such as returned from a server side object or remote service call; you can set the label's text in ActionScript:

dateLabel.text = myDateObject.toDateString();
timeLabel.text = myDateObject.toTimeString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM