0

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.

1
  • Does it have to be this exact string, or can it also be something like 'May 24, 2020 15:34:00' or any other format that complies with RFC 2822 timestamps or ISO8601? Commented May 4, 2020 at 9:18

2 Answers 2

1

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");
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.