Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-将日期从一种格式更改为另一种格式_Javascript_Date_Split - Fatal编程技术网

Javascript-将日期从一种格式更改为另一种格式

Javascript-将日期从一种格式更改为另一种格式,javascript,date,split,Javascript,Date,Split,我有这样一个字符串U{11/12/2016}11/12/2016[19:24:42],需要将它转换为这样一个字符串2016-12-11T19:24:42,其中“2016-12-11是{code>之外的日期” 有什么想法吗?我该怎么做 提前谢谢,对不起,我的英语不好 string.split('}')[1].replace('[', 'T').replace(']', '').replace(/\//g,'-') 就这样 const string='U{11/12/2016}11/12/201

我有这样一个字符串
U{11/12/2016}11/12/2016[19:24:42]
,需要将它转换为这样一个字符串
2016-12-11T19:24:42
,其中“2016-12-11是
{code>之外的日期”

有什么想法吗?我该怎么做

提前谢谢,对不起,我的英语不好

string.split('}')[1].replace('[', 'T').replace(']', '').replace(/\//g,'-')
就这样

const string='U{11/12/2016}11/12/2016[19:24:42];
console.log(
string.split('}')[1]。replace('[','T')。replace(']','')。replace(//\//g,'-'))

)
您可以使用正则表达式:

s.replace(/.*\}(\d+)\/(\d+)\/(\d+)\[(.*)\]/, '$3-$2-$1T$4')

谢谢,就快到了!只需将日期类型“11-12-2016”更改为“2016-12-11”就可以了。因此,添加相同的指令
.split('T').map((e,i)=>i?e:split('-').reverse().join('-')).join('T')