Flex time analysis

Is there a way to parse a string in HH: MM format into a Date (or other) object using standard libraries?

I know that I can parse something like "9/17/2008 10:30" into a Date object using

var date:Date = new Date(Date.parse("9/17/2008 10:30");

But I want to make out only 10:30. The following code will not work.

var date:Date = new Date(Date.parse("10:30");

I know that I can use a special RegEx for this quite easily, but it looks like it should be possible using the existing Flex API.

+3
source share
4 answers

: , , , ISO , ..

? .

0

, , .

( ):

var str:String = "9/17/2008 10:30"

var items:Array = str.split(" ");
var dateElements:Array = items[0].split("/");
var timeElements:Array = items[1].split(":");

var n:Date = new Date(dateElements[2],
                        dateElements[0],
                        dateElements[1].
                        timeElements[0],
                        timeElements[1]);

24 , AM PM ( AM).

+3

, DateField:

  • DateField.stringToDate(valueString: String, inputFormat: String):
  • DateField.dateToString(: Date, outputFattern: String): String

, , // ( ).

In your particular case: the Date object always also contains information about the "date". If that doesn't matter, could you just concatenate the standard date string before parsing?

+2
source

Do you think that “01/01/2000” is indicated in the time line, and then apply Date?

Alternatively, there may be a tokenizer that will take input and split it by:, providing you with an array of strings that you can convert to integers. The tokenizer is also not difficult to write, and can be funny if it does not exist in flex.

-Adam

+1
source

Source: https://habr.com/ru/post/1697057/


All Articles