PrettyTime Documentation

repository·master·Indexed 23 days ago

https://github.com/ocpsoft/prettytime

A social-style date and time formatting library for Java that provides human-readable relative time strings. Includes installation guides for Android, versioning requirements for Java 1.7 and 1.8+, and documentation for using PrettyTime JSTL tags in JSP.

Tokens
761
Snippets
4
Records
5
Agent score
30%

What's inside PrettyTime

  1. Use PrettyTime JSTL tags in JSP

    master

    To use PrettyTime for human-readable date formatting in a JSP file, declare the tag library and then use the <ocpsoft:prettytime> tag.

    1. Declare the tag library: Add the following directive to the top of your JSP file: <%@ taglib prefix="ocpsoft" uri="http://ocpsoft.org/prettytime/tags" %>

    2. Use the tag: Pass a date object to the date parameter. You can optionally specify a locale to localize the output.

    <ocpsoft:prettytime date="${myDate}" locale="en_US"/>
    <%@ taglib prefix="ocpsoft" uri="http://ocpsoft.org/prettytime/tags" %>
    
    <ocpsoft:prettytime date="${myDate}" locale="en_US"/>
  2. Install PrettyTime for Android

    master

    To use PrettyTime in an Android project, add the following dependency to your app-level build.gradle file:

    implementation 'org.ocpsoft.prettytime:prettytime:5.0.8.Final'

    ProGuard/R8 Configuration

    • If you use the R8 shrinker (default in Android Gradle Plugin 3.4.0+), ProGuard rules are automatically configured.
    • If you use an older version of AGP, you must manually add the ProGuard rules found in core/src/main/resources/META-INF/proguard/prettytime.pro.

    Compatibility Note

    If your project's minSdkVersion is below 26, you must enable API desugaring to support the required Java 8+ features.

  3. Run the PrettyTime JSTL integration sample

    master

    You can run the provided sample web application using Maven. This will launch a local server where you can view the PrettyTime JSTL integration in action.

    1. Build and run the application:

    mvn install && mvn exec:java -PrunJstlSample

    1. Access the sample at:

    http://localhost:8080/index.do

    mvn install && mvn exec:java -PrunJstlSample
  4. Choose the correct PrettyTime version based on Java/JDK

    master

    PrettyTime version selection depends on your project's Java/JDK version:

    • Java 1.8 or higher: Use version 5.0.0.Final or higher.
    • Java 1.7 or lower: Use versions in the 4.x branch (e.g., 4.0.6.Final or lower).
  5. Reference PrettyTime JSTL tag parameters

    master

    The <ocpsoft:prettytime> tag accepts the following parameters:

    | Parameter     | Required | Description | Default value                                                |
    |:-----------   |:--------:|:------------------------------------------ |:----------------------------------------------|
    | date          | yes      |    The date object to pretty print         | N/A                                                |
    | locale        | no       |    The locale used to localize the message | default locale                                     |