使用多个字符分割字符串
我需要的是简单的东西,我有一个包含数据的字符串 - 以 mySQL 格式 HH:MM:SS YY-MM-DD 从 mySQL 检索的时间 我需要的是将动作脚本中的这个字符串拆分为这样的数字数组 赫赫 毫米 SS YY 毫米 DD
所以我可以将它与当前时间进行比较,任何人都知道如何首先使用多个分隔符进行分割,然后将其与当前时间进行比较。这是我到目前为止的工作
var param:Array = datetime.split(" :-");
var currentTime:Date = new Date();
var seconds:uint = currentTime.getSeconds();
var minutes:uint = currentTime.getMinutes();
var hours:uint = currentTime.getHours();
var days:uint = currentTime.getDay();
var monthes:uint = currentTime.getMonth();
var years:uint = currentTime.getFullYear();
if(int(param[3]) > years)
return years + " سنة ";
if(int(param[4]) > monthes)
return monthes + " شهر ";
if(int(param[5]) > days)
return days + " يوم ";
if(int(param[0]) > hours)
return hours + " ساعة ";
if(int(param[1]) > minutes)
return minutes + " دقيقة ";
if(int(param[2]) > seconds)
return seconds + " ثانية ";
return param[0] + " يوم ";
`
what I need is simple thing, I have string which cantains data - time retrived from mySQL in mySQL format HH:MM:SS YY-MM-DD what I need is to split this string in actionscript to array of numbers like this
HH
MM
SS
YY
MM
DD
so I can compare it with current time, any one know how to splite using multiple delimiters at first, then compare it with current time. this is my work until now
var param:Array = datetime.split(" :-");
var currentTime:Date = new Date();
var seconds:uint = currentTime.getSeconds();
var minutes:uint = currentTime.getMinutes();
var hours:uint = currentTime.getHours();
var days:uint = currentTime.getDay();
var monthes:uint = currentTime.getMonth();
var years:uint = currentTime.getFullYear();
if(int(param[3]) > years)
return years + " سنة ";
if(int(param[4]) > monthes)
return monthes + " شهر ";
if(int(param[5]) > days)
return days + " يوم ";
if(int(param[0]) > hours)
return hours + " ساعة ";
if(int(param[1]) > minutes)
return minutes + " دقيقة ";
if(int(param[2]) > seconds)
return seconds + " ثانية ";
return param[0] + " يوم ";
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Split 允许分隔符是正则表达式,因此您可以这样说或那样说。就像这样:
祝你好运!
Split allows the delimiter to be a regexp, so you can say this or that. Something like this:
Good luck!
您可以使用多个字符,并用管道 | 分隔。
如果您使用 ( ) 和类似的内容,请确保使用 \,因此 ( )
You can use multiple characters, with separated by pipe |
make sure to use \ if you use ( ) and similar, so ( )
为了解决您的具体问题,您可以考虑将字符替换为相同的字符,然后拆分该字符。使用Tyler 说的更优雅:datetime.replace(/[ :-]/g, "|")
,然后按“|”拆分。 (我没有检查正则表达式的正确性)。datetime.split(/[ -:]/)
。不过,我代表其余的:MySQL 输出(通过 php?)是标准日期表示法。您可以尝试使用 Date.parse(dateString ) 从中获取时间戳,并将其作为唯一的构造函数参数传递,将其转换为日期对象:
然后您可以直接比较两个日期对象。
希望有帮助。
To solve your specific question, you might consider replacing the characters to be the same, and then split on that one. UseWhat Tyler says is more elegant:datetime.replace(/[ :-]/g, "|")
and then split on "|". (I didn't check the correctness of the regexp).datetime.split(/[ -:]/)
. I stand for the rest though:What MySQL outputs (via php?) is a standard date notation. You could try and use the Date.parse(dateString) to get a timestamp from it, and convert that into a date object by passing it as the sole constructor parameter:
You could then compare the two date objects directly.
Hope it helps.