0

I have the following date string 2020-01-17T06:41:48.000Z.

I would like to convert it to such as 15810232300 which is milliseconds type in mac os shell.

How to achieve it?

  • Your example number value isn't milliseconds; you need two more digits for that. – roaima Jan 17 at 8:40
1

You can install coreutils which contains GNU date :

brew install coreutils

then

$ gdate -d "2020-01-17T06:41:48.000Z" +%s%3N
1579243308000
|improve this answer|||||
0

With the BSD date supplied in OSX, you can

timestring="2020-01-17T06:41:48.456Z"
/bin/date -jf "%Y-%m-%dT%H:%M:%S" "${timestring%.???Z}" "+%s${timestring: -4:3}"
1579261308456
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.