美文网首页
ios端时间字符串转换成斜杠

ios端时间字符串转换成斜杠

作者: zhcnnet | 来源:发表于2020-08-19 09:51 被阅读0次

再ios端2020-08-02这样的时间会出错,为了方便可以写个方法来转换一下。

String.prototype.convertToSlash = function (): string {
    return this.toString().replace(/-/g, '/');
}

//还可以这样
String.prototype.toDate = function (): Date {
    return new Date(this.convertToSlash());
}

// 使用方法
"2020-08-02".convertToSlash();
"2020-08-02".toDate();

相关文章

网友评论

      本文标题:ios端时间字符串转换成斜杠

      本文链接:https://www.haomeiwen.com/subject/qnhrjktx.html