Some Scala Long, Date, and SimpleDateFormat examples

At some point I’ll get all of my Scala “date utilities” together in a single class (object, actually), but until then, here are a couple of date utility methods I wrote for my Scrupal6 project (a replacement for Drupal 6):

Scala: How to get the current month as a number or string alvin March 22, 2018 - 3:02pm
Table of Contents1 - Get the current month as an integer number2 - How to get the current month as an abbreviated string3 - How to get the full month name4 - A note about SimpleDateFormat and Locale5 - Summary

Scala FAQ: How do I get the current month as an integer or as a string in Scala?

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:

A Scala current date and time example

Scala date/time FAQ: How do I get the current date and time in Scala?

Getting the current time

The following code demonstrates how to get the current time in Scala, and then further shows how to get other information, such as the current minute, using the Java SimpleDateFormat class:

Java Date format example - Format a Date so humans can read it

Java Date format FAQ: Can you show me how to format a Java Date object in a human-readable format?

It's pretty easy to get a Date in a Java program, but it takes a little more work to print a Date in a human-readable format. This article shows how to print a date in a human-readable format.

Java Date format example

Here's a snippet of Java date formatting code I'm working on right now:

Java Date FAQ: How do I get today’s date?

Java Date FAQ: Can you show me how to get today's date in Java?

Getting a Java Date object that represents "today" or "now" is fairly simple. The following sample code shows how to do this:

Date date = Calendar.getInstance().getTime();

If you haven't worked with the Java Date class before, I should point out that I'm referring to a java.util.Date class here, and not a java.sql.Date class. To make this a little more clear, I could write that same code like this: