我在react.js 文件中有一个方法,可以将日期保存在下面的bigint 字段中
getTodaysDate(){
let formatTwoDigits = (digit) => ("0" + digit).slice(-2);
var tempDate = new Date();
var date = `${tempDate.getFullYear()}${formatTwoDigits(tempDate.getMonth()+1)}${formatTwoDigits(tempDate.getDate())}${formatTwoDigits(tempDate.getHours())}${formatTwoDigits(tempDate.getMinutes())}${formatTwoDigits(tempDate.getSeconds())}`;
return date;
}
这是sql数据库中保存的内容
20190313133112
我想读出此内容并以如下所示的有意义的格式显示
mm/dd/yyyy [3/13/2019]
如何将此存储的日期转换为上面的正常日期?
最佳答案
您可以使用替换。
^(\d{4})(\d{2})(\d{2}).*
| | | |_____ Anything except new line
| | |
| | |_________ Day ( group 3 `$3`)
| |
| |_________________ Month ( group 2 `$2`)
|
|_________________________ year ( group 1 `$1`)
let str = `20190313133112`
let op = str.replace(/^(\d{4})(\d{2})(\d{2}).*/,"$2/$3/$1")
console.log(op)
关于javascript - 将 bigint 字段中存储的日期转换为正常日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55149179/