The DateTime class is used for parsing, storing, and manipulating Date and Time. It also incorporates the ability to format dates in its toString output in a couple of ways.
By default, DateTime will use the format defined in its associated DateTimeConfig. You can override this format by specifying a custom format as a parameter. Here's an example:
DateTime dt=new DateTime("2011-10-05");
system.out.println(dt.toString("yyyy-MM-dd"));
The formatting options behave the same as the SimpleDateFormat provided in the Java language, with a few exceptions.
| Format character | Java behavior | POJava behavior |
| g | Unsupported | Scientific Era Designator CE/BCE |
| G | Era Designator | Same |
| M | Month in Year | Same |
| y | Year | Same |
| d | Day in Month | Same |
| D | Day in Year | Same |
| E | Day in Week | Same |
| a | Am/Pm Marker | Same |
| h | Hour in am/pm 1-12 | Same |
| H | Hour in Day 0-23 | Same |
| k | Hour in Day 1-24 | Same |
| K | Hour in am/pm 0-11 | Same |
| m | Minute in Hour | Same |
| s | Second in Minute | Same |
| S | Millisecond | Fractional Second |
| z | General Time Zone | Same |
| Z | RFC 822 Time Zone | Same |
| F | Day of Week in Month | Same |
| w | Week in Year | Same |
| W | Week in Month | Same |