I want to convert a string "24.05.2020 15:34:00" into a Unix timestamp in javascript. Can any one tell how to do that? thanks.
You can do it with combination of Ext.Date.parse
and Ext.Date.format
.
Ext.Date.parse
to make Date Object from String
Ext.Date.format
to make timestamp from Date Object.
Ex.
Ext.Date.format(Ext.Date.parse("24.05.2020 15:34:00", "d.m.Y H:i:s"), "time");
in JavaScript:
var s="24.05.2020 15:34:00".split(' '); var d=s[0].split('.'); var t=s[1].split(':'); var jt=new Date(d[2],d[1]-1,d[0],t[0],t[1]); var ut=jt.getTime()/1000; console.log(ut);
On line 4 d [1] -1 because we count months from 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.