问题描述:

I've got a php backend which delivers a time (e.g. '07:00:00').

This time is recognized as a string but I need it as a Date.

So what I need is:

Convert a string '07:00:00' to a Flex Date object.

Is there a way to do this (without using regular expressions)?

网友答案:
  • String.split(":") -> array of "07", "00", "00"
  • parseInt on each part
  • create date object and use setHours, setMinutes and setSeconds methods.

Don't forget that newly created Date object presents current date.

网友答案:

Use the Date class http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/

Particularly the parse() property , but you should also be able to use a PHP timestamp and get the Date class to return a String

  //value returned from PHP
  var timestamp:Number = 1234670090;
  var date:Date = new Date(timestamp);

  var date2:Date = new Date();
  var time:String = date2.parse('07:00:00');

  // trace( date ) or trace( time ) should give you a String 
  //with the format Sat Nov 30 15:20:00 GMT-0800 1974

You can use the date variable's properties to return the year , month , day , hours, minutes etc...

相关阅读:
Top