灵活 – 简单的英语解析时间

前端之家收集整理的这篇文章主要介绍了灵活 – 简单的英语解析时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想找到一个可以采取以下字符串的actionscript库:

>两天
> 2h
>一个月
>一周

并将其解析为持续时间(在某些单位返回时间).

以前好像已经做了很多次了,我不喜欢自己实现这样的事情.

如果不在actioncript然后在python(我可以运行在服务器端我猜).

(请注意,我正在寻找解析,而不是格式化..)

解决方法

只是为了记录,Javascript将不会直接在Flex中工作.确定你知道这一点.

现在,datejs是一个非常酷的库.你应该真正做的是使用externalInterface类在AS中使用JS的优点.

在AS3中使用以下代码,并确保在html包装器中包含datejs.js,其中将使用此AS3生成的swf.

//--------CODE IN AS-----------------//
public function returnDate(date:String):void
{
    Alert.show(date);
}

ExternalInterface.addCallback("returnDate",returnDate);

public function parseDate(userInputString:String):void
{
   ExternalInterface.call("parseStringByUser",userInputString);
}

//------------CODE IN JS----------------//
function parseStringByUser(userInputString)
{
     var parsedDate= Date.parse(userInputString);
     //the line below calls the AS3 function,as AS3 itself exposed it using the ExternalInterface.
         returnDate(parsedDate);
}

对于externalInterface的详细信息,您可以查看:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html

原文链接:https://www.f2er.com/flex/174158.html

猜你在找的Flex相关文章