javascript - JS。从字符串中获取部分日期
问题描述
我有这个字符串 '2020-10-20' 我可以像这样分别得到这些数字吗:
const [year, month, day] = '2020-10-20'.match(/\d\d\d\d/ what should i write there?)
还是存在更好的方法?
解决方案
您可以使用分隔符拆分字符串,如下所示
const [year, month, day] = '2020-10-20'.split("-")
那么你会有year=2020
等。
推荐阅读
- ios - 如何获得 MobileVLCKit 的缓冲区百分比?
- python - 如何将 scrapy 与我的烧瓶应用程序集成?
- gatsby - 我无法在 netlify 中访问我的环境变量
- c# - Asp.net MVC 将数据发布到控制器
- c# - Android:通过蓝牙将元数据从媒体播放器应用程序发送到汽车音响阻止广播接收器播放下一首歌曲或暂停音乐
- java - 增加彩信图片的宽度和高度
- javascript - 65536 处的 getSelection() 错误
- python - 获取在 Python 中调用方法的对象
- python - Matplotlib:所有组的堆积面积图
- c# - 如何在具有 MVC 5 的类库项目中使用 Entity Framework 6 Code First