Unix timestamp to datetime string

JavaScript (ES6), 65 bytes

n=>'101010.1010'.replace(i=/\d/g,x=>new Date(n).toJSON()[i=x-~i])

Try it online!

How?

We initialize the pointer \$i\$ to a non-numeric value (coerced to \$0\$) and then add alternately \$2\$ and \$1\$ to it to pick the relevant characters from the ISO-8601 conversion of the input timestamp.

yyyy-mm-ddThh:mm:ss.sssZ
  ^^ ^^ ^^ ^^ ^^

JavaScript (ES6), 66 bytes

n=>'235689.BCEF'.replace(/\w/g,x=>new Date(n).toJSON()[+`0x${x}`])

Try it online!

How?

Once the input timestamp is converted in ISO-8601 format, all required characters can be accessed with a single hexadecimal digit.

yyyy-mm-ddThh:mm:ss.sssZ
  ↓↓ ↓↓ ↓↓ ↓↓ ↓↓
0123456789ABCDEF

Bash + coreutils, 29 bytes

date -d@${1::-3} +%y%m%d.%H%M

Try it online!


PHP, 40 32 31 bytes

-8 bytes thanks to Luis felipe
-1 byte thanks to Jo King

<?=date('ymd.hi',$argv[1]/1e3);

Try it online!

Simple naive answer. PHP's date function takes a format string and an integer timestamp. Input from cli arguments, which is a string by default, then /1e3 because date expects second-precise timestamps. This also coerces the string to a number.

Tags:

Date

Code Golf