2023-09-09转成2023.09.09-前端-E先生的博客
Java
MySQL
大数据
Python
前端
黑科技
大语言模型
    首页 >> 互联网 >> 前端

2023-09-09转成2023.09.09

[导读]:你可以将日期字符串中的短划线 "-" 替换成点号 "." 来实现这个格式的转换。以下是一个示例:constdateStringWithHyphen="2023-09-09";constdateStringWithDot=dateStringWithHyphen.replace(/-/g,'.');console.log(dateStringWithDot...

你可以将日期字符串中的短划线 "-" 替换成点号 "." 来实现这个格式的转换。以下是一个示例:

const dateStringWithHyphen = "2023-09-09";
const dateStringWithDot = dateStringWithHyphen.replace(/-/g, '.');
console.log(dateStringWithDot); // 输出 "2023.09.09"

在上述示例中,我们使用了字符串的 replace 方法和正则表达式 /-/g 来查找并替换所有的短划线 "-" 为点号 ".",从而将日期格式从 "2023-09-09" 转换为 "2023.09.09"。


image.png

本文来自E先生的博客,如若转载,请注明出处:https://www.javajz.cn

留言区

联系人:
手   机:
内   容:
验证码:

历史留言

欢迎加Easy的QQ