javascript - 将文本格式日期更改为日期格式
问题描述
嗨,我在多个列中有一组日期。
我需要将此单元格格式化为DD-MM-YYYY
.
在谷歌表中更改为的日期"Mon Jun 01 10:06:35 2020"
格式01-06-2020
请以我可以在任何谷歌表格中使用它的方式共享代码。
解决方案
这是一个可能的解决方案:
function convertDate(x){
const myDate = new Date(x);
const day = myDate.getDate();
const month = myDate.getMonth() + 1;
const year = myDate.getFullYear()
const formattedDate = `${day < 10 ? "0"+day : day}-${month < 10 ? "0"+month : month}-${year}`;
return formattedDate;
}
console.log(convertDate("Mon Jun 01 10:06:35 2020"));
//Output: "01-06-2020"
推荐阅读
- perl - Perl CGI::Session 开始问题
- python-3.x - 连接拒绝远程运行在 Docker 容器上的 Spark Master
- reactjs - 为什么 hls.js 库会导致视频质量下降,而原生 Apple 流媒体库运行良好?
- adobe - INVALID_X_API_USER_HEADER
- java - 如何在房间数据库中将列名作为参数传递?
- php - laravel 不更新数据,只刷新
- node.js - 具有 _id 关系的类型的最后一个值
- php - 循环时检查数组的先前元素
- angular-reactive-forms - Angular 9 反应式表单中的验证器比较密码
- javascript - 在数组中的多个项目中分配货币/数字