Announcement Announcement Module
No announcement yet.
DateTimeFormat for just day of week and time. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • DateTimeFormat for just day of week and time.

    I have a Date field and I want the format to be something like this: "Monday 8:00AM".
    What is the pattern to show the day of the week?

  • #2
    I've been meaning to look into date formatting. With annotations, it looks like you can only use the standard Joda styles. From the Joda JavaDoc, "The first character is the date style, and the second character is the time style. Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full. A date or time may be ommitted by specifying a style character '-'."

    So I tried pulling in the addDateTimeFormatPatterns method from my controller .aj to the controller .java. I simply hard-coded the format like below. And it worked!

    void addDateTimeFormatPatterns(Model uiModel) {

    // uiModel.addAttribute( "tour_lastskated_date_format", DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale())); //generated code
    uiModel.addAttribute("tour_lastskated_date_format" , "EEEE h:mma");