·¬ÇÑÉçÇø

Brightspot CMS Developer Guide

Formatting dates using view models


You can set the default date format from within the content type’s view model. When resolving the date format to use, Brightspot checks for this configuration if there is no date format specified in a theme’s properties (as described in Date formats and resource bundles) or in a site’s settings.

import brightspot.view.core.article.ArticlePageView;
import brightspot.core.tool.DateTimeUtils;
import brightspot.core.page.CurrentPageViewModel;
import com.psddev.cms.view.PageEntryView;
import com.psddev.cms.view.ViewModel;

public class ArticlePageViewModel extends ViewModel<Article> implements ArticlePageView, PageEntryView {

    @CurrentPageViewModel 
    protected PageViewModel page;

    private static final String DATE_FORMAT_KEY = "dateFormat"; 
    private static final String DEFAULT_DATE_FORMAT = "MMMM d, yyyy"; 

    @Override
    public CharSequence getDatePublished() { 
        return DateTimeUtils.format(model.getPublishDate(), ArticlePageView.class, DATE_FORMAT_KEY, page.getSite(), DEFAULT_DATE_FORMAT);
    }

}
  • Declares a variable page, and the annotation assigns it the default value PageViewModel class.
  • Declares a date format string.
  • Retrieves the model's publication date and outputs the date using the configured format string.

See also:

Previous Topic
Installing additional dictionaries
Next Topic
Customizing the search experience
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

•
•
•
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

• Content types
• Modules
• Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

• Dashboards
• Publishing
• Workflows
• Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

• Field types
• Content modeling
• Rich-text elements
• Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

• Google Analytics
• Shopify
• Apple News