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 FAQ: How do I get the current month as an integer or as a string in Scala?
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
Summary: This tutorial demonstrates how to use the Java SimpleDateFormat class to convert a Java
Date to a formatted
Summary: A Java SimpleDateFormat (date formatting) example, showing how to convert a Java String to a Date.
In an earlier example I showed how to use the Java SimpleDateFormat class to convert from a Date to a String, but you can also use the Java
SimpleDateFormat class to convert in the opposite direction, from a given Java
String to a
Java Date format FAQ: Can you show me how to format a Java Date object 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: 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: