- Pretty time format is used mainly in social media site like twitter, Facebook. If you mark your posts in Facebook then you can see message like “posted 2mins ago”, “posted 1day ago”.
These formats are pretty time format.
- Download the jar file from:-
http://repo1.maven.org/maven2/com/ocpsoft/ocpsoft-pretty-time/1.0.7/ocpsoft-pretty-time-1.0.7.jar
Project Structure:-
Test the Pretty Time:-
package com.sandeep.pretty.demo;
import java.util.Calendar;
import java.util.Date;
import com.ocpsoft.pretty.time.PrettyTime;
public class TestPrettyTimeDemo {
public static void main(String []args){
PrettyTime ptime = new PrettyTime();
System.out.println(ptime.format(new Date())); //today
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1); //yesterday
System.out.println(ptime.format(cal.getTime()));
cal.add(Calendar.YEAR, -10);//10 years back
System.out.println(ptime.format(cal.getTime()));
}
}