© Moritz Lenz 2020
M. LenzRaku Fundamentals https://doi.org/10.1007/978-1-4842-6109-5_4

4. Datetime Conversion for the Command Line

Moritz Lenz1 
(1)
Fürth, Bayern, Germany
 

Occasionally I work with a database that stores dates and datetimes as UNIX timestamps, a.k.a. the number of seconds since midnight 1970-01-01. Unlike the original author of the database and surrounding code, I cannot convert between UNIX timestamps and human-readable date formats in my head, so I write tools for that.

Our goal here is to write a small tool that converts back and forth between UNIX timestamps and dates/times:
$ autotime 2015-12-24
1450915200
$ autotime 2015-12-24 11:23:00
1450956180
$ autotime 1450915200
2015-12-24
$ autotime 1450956180
2015-12-24 11:23:00

4.1 Libraries ...

Get Raku Fundamentals: A Primer with Examples, Projects, and Case Studies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.