谁能帮我将日期格式 27.05.2015 01:46:32.UTC
转换为区域设置时间。
我尝试了以下代码
var date = new Date('27.05.2015 01:46:32.UTC ');
date.toString();
这也不起作用。
即使 momentjs
转换这种日期格式也会出错。
最佳答案
根据声明甚至momentjs在转换这种日期格式时也会出错,我冒昧地使用了momentjs在这里。
您需要使用string-format moment 构造函数传递字符串和输入字符串的格式。
使用
var t = "27.05.2015 01:46:32.UTC";
//pass dateTime string and its format, it will return
//moment object
var cdt = moment.utc(t, 'DD.MM.YYYY HH:mm:ss');
//Get date object
var date = cdt.toDate();
//Use date variable as per requiremnt
alert(date);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script>
关于javascript - 将日期格式 27.05.2015 01 :46:32. UTC 转换为区域设置时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30523071/