views:

19

answers:

2

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)?

+1  A: 
  • 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.

alxx
This is like using regular expressions for me. I'm searching for something like the Date.parse() function.But your answer is right, I should've been more detailled.
hering
NB: in flex the days (Date.date) start at 1, but the months (Date.month) start at 0. Could miss this when converting from the PHP date. Little brat of a problem caught me out before!
Brian Bishop
A: 

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...

PatrickS
Seems, that you missunderstood me:I don't have a timestamp. All i got is '07:00:00'. And `Date.parse("07:00:00");` won't work.
hering
PatrickS
The thing is: I don't care about year, month and day. It's just the time I need. Your guess about the Date class is right. I thought there is a possibility to leave the year, month and day empty.
hering