Hello guys,
Some programmers many time faces difficulty while changing date format in liferay. Therefore By Below example, I am going to guide you How to change date format in liferay?
Given bellow is the date format in GMT of liferay
"E MMM dd HH:mm:ss 'GMT' yyyy" 4 Nov 2014 10:08:28 GMT
Now , retrieve record created date :
List<DDLRecord> ddlRecordnew = null;
try {
ddlRecordnew = DDLRecordLocalServiceUtil.getDDLRecords(-1,Integer.MAX_VALUE);
if (ddlRecordnew != null) {
for (int i = 0; i < ddlRecordnew.size(); i++) {
String createDate=ddlRecordnew.get(i).getCreateDate().toGMTString();
System.out.println(createDate);
// output :4 Nov 2014 10:08:28 GMT
}
}
}
catch(Exception e)
{
}
If you want to change date format of createDate
//applyPattern("E MMM dd HH:mm:ss 'GMT' yyyy"); 4 Nov 2014 10:08:28 GMT
Date dt = new SimpleDateFormat("d MMM yyyy HH:mm:ss 'GMT'").parse(createDate);
//applyPattern("yyyy/MM/dd");
String createDate = new SimpleDateFormat("yyyy/MM/dd").format(dt);
0 Comment(s)