I have this date
Sep 7, 2019, 1:00 PM CEST
and want to convert it into a timestamp.
How would I go about doing this?
I have this date
Sep 7, 2019, 1:00 PM CEST
and want to convert it into a timestamp.
How would I go about doing this?
Replace CEST
-> (CEST)
and try to convert like below,
new Date("Sep 7, 2019, 1:00 PM CEST".replace('CEST', '(CEST)'))
Solution implemented based on this valuable article. Credit goes to article author :)
This answer is more of a pseudo-code then an exact javascript code.
The format of the string (posted by OP) is not supported natively. One of the answers used moment's moment
function with second argument to parse the timezone i.e. CEST
part in the querying string basically, but I found that conversion faulty too - https://www.epochconverter.com/timezones?q=1567841400&tz=Europe%2FBerlin - wondering what is 1567841400
try running this answer - https://stackoverflow.com/a/57830429/7986074
So the code would look like this -
CEST
- one may use ''.substr
Date
or moment
You might need to convert your CEST
to GMT+0200
which contains the timezone and the offset as well.
const date = new Date('Sep 7, 2019, 1:00 PM CEST'.replace('CEST', 'GMT+0200'));
console.log(date);
Did you try passing that string directly into the Date constructor? But before you have to get rid of the timezone. Here is an easy example:
// 1. A variable with your date as a string literal
const dateStr = "Sep 7, 2019, 1:00 PM CEST"
// 2. Get rid of the timezone and use the result to instantiate a new date
const d = new Date(dateStr.slice(0,-4))
// 3. Now that you have your date instance, use getTime() method to get the timestamp
const timestamp = d.getTime()
Hope my answer can help you!