我知道要将 C# 日期(如 /Date(1430341152570)/
)转换为 JavaScript 日期,如下所示:
var part = "/Date(1430341152570)/".substr(6); // => "1430341152570)/"
var jsDate = new Date(parseInt(part));
我的问题:如何通过 parseInt
将包含尾随 )/
的 part
值解析为 int? JS 不会在尝试转换具有 )/
字符的内容时抛出错误吗?如果 part
值类似于 "/Date(......)/".substr(6).replace(')/',对我来说会更有意义, '')
b/c 至少你正在将它变成一个要解析为 int 的字符串。
最佳答案
If
parseInt
encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point.parseInt
truncates numbers to integer values. Leading and trailing spaces are allowed.
)
不是数字,因此按照指定从那里开始的所有内容都将被忽略。
或来自ES6 draft standard :
parseInt
may interpret only a leading portion of string as an integer value; it ignores any code units that cannot be interpreted as part of the notation of an integer, and no indication is given that any such code units were ignored.
关于javascript - 将 c# 日期解析为 javascript 日期如何与 ')' 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29967599/