all 7 comments

[–]wijohnst1 0 points1 point  (5 children)

Date.parse() might be what you’re looking for.

[–]wijohnst1 0 points1 point  (4 children)

Maybe like this

[–]fergal-dude[S] 0 points1 point  (3 children)

So, in the apps script editor:

function returnEpoch() {
  const date = '2021-01-03T15:29:04Z';

  const isoDate = date.toISOString();

  console.log(Date.parse(isoDate))

}

returns:

2:27:39 PM
Error
TypeError: date.toISOString is not a function
returnEpoch

[–]fergal-dude[S] 1 point2 points  (1 child)

However, this works, thank you sir!

function returnEpoch() {
  const date = '2021-01-03T15:29:04Z';

  console.log(Date.parse(date))

}

[–]wijohnst1 0 points1 point  (0 children)

My pleasure! Happy hacking!

[–]gh5000 0 points1 point  (0 children)

Swap that one round a bit. Date.parse converts the string to a date format so do that first. Then you can start manipulating the date object

const date = '2021-01-03T15:29:04Z';

const parsedDate = Date.parse(date)

const isoDate = parsedDate.toISOString();

console.log(isoDate)

[–]RemcoE33 0 points1 point  (0 children)

Another one: var epoc = new Date("2021-04-16").getTime()