[英]Converting UTC date to mm/dd/yyyy
I am having a date in isoUtc format and I want to convert it into mm/dd/yyyy format. 我有一个isoUtc格式的日期,我想将其转换为mm / dd / yyyy格式。 I tried to use the hint given in this blog entry but the problem I am facing is that if I convert
2007-04-06T00:00Z
it gives different dates when user time zone is different. 我尝试使用此博客文章中给出的提示,但我面临的问题是,如果我转换
2007-04-06T00:00Z
,则当用户时区不同时,它会给出不同的日期。 I want that it should give 04/06/2007
always independent of the user timezone. 我希望它应始终与用户时区无关地给
04/06/2007
。
Any help is appreciated 任何帮助表示赞赏
You could thy this, if you have always constant format: 如果您始终使用恒定格式,则可以这样做:
var dateString = '2007-04-06T00:00Z',
dateRegExp = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/,
match = dateString.match(dateRegExp),
date;
if (match) {
date = new Date(match[1], match[2] - 1, match[3], match[4], match[5]);
console.log(date);
}
var d = '2007-04-06T00:00Z';
var d2 = d.substring(5,7)+'/'+d.substring(8,10)+'/'+d.substring(0,4);
// outputs 04/06/2007
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.