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

我想找到一个可以采取以下字符串的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

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...