date

How to create a Java or Scala date from a Long value alvin April 7, 2018 - 5:09pm

Scala FAQ: How do I created a Scala Date from a Long value? When I give the Java Date class constructor a Long value it returns a date from 1970.

Solution: You need to multiply the Long value by 1000, and also make sure you pass a Long value into the Date constructor. The Scala REPL shows how this works:

Format of the Linux crontab date and time fields

I’ve written several things about the Linux cron command and crontab file format before, and as a quick note, here’s some information on the format of the crontab date and time fields.

Crontab date/time fields

First, from the crontab man page documentation:

Scala number, date, and formatting examples

This short blog post contains a collection of Scala number and date examples. I created most of these in the process of writing the Scala Cookbook. Unlike the Cookbook, I don’t describe the examples here much at all, I just show the examples, mostly as a reference for myself (and anyone else that can benefit from them).

Scala numeric types

Scala has these numeric types:

Two “okays,” and those shoes

After working until one o’clock this morning, I had barely woken up at 9:30am when someone kept knocking insistently on my apartment’s front door. I was dressed in old blue sweatpants with dried streaks of clay on them, a bright orange beach shirt, slippers, haven’t shaved in three days, just out of bed hair, green under the eyes because that’s what they look like when I wake up (thanks to the MCAS), but I answered the door.

A woman I know was standing there. “Okay, that outfit is pretty ridiculous,” she said. “But I was thinking, we should go out some time.”

I didn’t answer because I wasn’t awake and was barely processing what she said and I don’t really go out (also thanks to the MCAS). Then she said, “I have to go to work now, but maybe we can talk later?”

“Okay.”

I’m still not awake, but she wears high heel shoes a lot, so she always makes me think of this Eagles song.

Scala “string to date” and “date to string” methods

Here are a couple of “string to date” and “date to string” methods. They’re written in Scala, but are easily converted to Java. They only use the Java Date and SimpleDateFormat classes:

Epoch Converter alvin March 1, 2015 - 12:34pm

The EpochConverter website can be useful, especially if you need to manually generate the “datetime” stamp for a Drupal theme’s .info file. The datetime field usually contains a Unix timestamp, like the one shown in the image.