【发布时间】:2017-03-20 07:27:58
【问题描述】:
今天我想请教一种比较有效的方法来转换custom formatted selectors to seconds。
如果我输入 '5d, 6h' 它应该输出 => [x 秒数]
其中选择器可以是任意数字> 999,并且支持minutes,seconds, hours, days, and years, where the preceding character is the selector, y for years, h for hours, and etc.。另一个例子是9d 4s,它仍然输出[x number of seconds]。两个“选择器”字符串存储在一个数组中。非常感谢!
【问题讨论】:
-
不客气 - 有什么代码可以分享吗?
-
@ScaryWombat 我没有,因为我正在询问解决它的好方法。我可以自己写,只是想弄清楚该怎么做。
-
所以如果输入包含
h使用选择器1,否则使用选择器2? -
不,两者都用。我会通过将它们加在一起来计算两者。例如,输入 1 => 5h 输入 2 => 2m 输出 => 18120 @ScaryWombat
-
YOU 如何手动操作?以与您相同的方式编写代码。