在 flex 中设置当前时间

Set current time in flex

我在我的应用程序中使用 DateField。

<mx:DateField id="dtNewDate" selectedDate="{new Date()}" change="{dtChangeHandler(event)}" />

在更改时我正在选择日期。而时间是00:00。
现在,我需要当前时间而不是 00。所以,我试过了。

public function dtChangeHandler(event:CalendarLayoutChangeEvent):void
{
  var df:DateFormatter =new DateFormatter();
  df.formatString="MM/DD/YYYY HH:NN:QQ";
  trace(df.format(event.currentTarget.selectedDate))
}

它将给出 24:00:00 而不是 00:00:00。有什么方法可以设置当前时间吗?

我也试过:

var date:Date = new Date();
selected_date = (event.currentTarget.selectedDate);
selected_date.setTime(date.getTime());

它将时间更改为当前时间。但是,它将日期更改为今天的日期。

任何帮助将不胜感激。

只需使用所选日期并覆盖其时间:

public function dtChangeHandler(event:CalendarLayoutChangeEvent):void
{
    var selectedDate:Date = event.currentTarget.selectedDate;
    var currentDate:Date = new Date();

    selectedDate.hours = currentDate.hours;
    selectedDate.minutes = currentDate.minutes;
    selectedDate.seconds = currentDate.seconds;

    trace(selectedDate);
}