我有一个这样的字符串:
I have a string like this:
21.03.2016 23:59
我需要将此字符串转换为 ISO-8601 日期时间字符串:
And I need this string converted into a ISO-8601 date-time string:
YYYY-MM-DDTHH:mm:ss+00:00
有没有简单的方法来转换这个日期?我尝试使用 moment.js,但找不到解析现有日期的函数.
Is there a simple way to convert this date? I try it whit moment.js but i can't find a function to parse an existing date.
你也可以不使用 moment.js 来做到这一点.看代码如下:
You can also do this without using moment.js. Look code as following:
(new Date("03.21.2016 23:59")).toISOString()
只需将字符串 21.03.2016 23:59 (dd-mm-yyyy) 更改为 03.21.2016 23:59 (mm-dd-yyyy).您可以通过拆分日期并更改拆分部分的顺序轻松做到这一点.
just you need to change your string 21.03.2016 23:59 (dd-mm-yyyy) to 03.21.2016 23:59 (mm-dd-yyyy). You can easily do this by split the date and change the order of split part.
如果您不想这样做,那么只需按照 matthias 的回答使用 moment.js.
And if you dont want to do this then simply use moment.js as per matthias's answer.
这篇关于Javascript - 将日期字符串重新格式化为 ISO8601的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
检查一个多边形点是否在传单中的另一个内部Check if a polygon point is inside another in leaflet(检查一个多边形点是否在传单中的另一个内部)
更改传单标记群集图标颜色,继承其余默认 CSSChanging leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改传单标记群集图标颜色,继承其余默认
触发点击传单标记Trigger click on leaflet marker(触发点击传单标记)
如何更改 LeafletJS 中的默认加载磁贴颜色?How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默认加载磁贴颜色?)
将 Leaflet 图层控件添加到侧边栏Adding Leaflet layer control to sidebar(将 Leaflet 图层控件添加到侧边栏)
Leaflet - 在弹出窗口中获取标记的纬度和经度Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在弹出窗口中获取标记的纬度和经度)