[opencms-dev] file modification time

Paul-Inge Flakstad flakstad at npolar.no
Mon Apr 18 17:24:49 CEST 2011


Hi Marko,

This is what I use:

<%@ page import="java.util.Locale,
                 java.util.Date,
                 java.text.SimpleDateFormat,
                 org.opencms.jsp.*,
                 org.opencms.file.*,
                 org.opencms.util.*" 
%><%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
CmsObject cmso = cms.getCmsObject();
String requestFileUri = cms.getRequestContext().getUri();
Locale locale = cms.getRequestContext().getLocale();

// See java.text.SimpleDateFormat for date format definitions
final String PAGE_DATE_FORMAT = "MMMM dd yyyy";

// The resource to investigate
CmsResource res = cmso.readResource(requestFileUri);

// The user who created the resource
CmsUser creatorUser = cmso.readUser(res.getUserCreated());
String creatorName  = creatorUser.getFirstname() + " " + creatorUser.getLastname();

// The user who modified the resource
CmsUser modUser = cmso.readUser(res.getUserLastModified());
String modifierName = modUser.getFirstname() + " " + modUser.getLastname();

// The resource's timestamps, as Date objects
Date modifiedDate = new Date(res.getDateLastModified());
Date createdDate = new Date(res.getDateCreated());

// The desired date format
SimpleDateFormat dFormat = new SimpleDateFormat(PAGE_DATE_FORMAT, locale);

// Print created & modified info
out.println("Created by " + creatorName + " at " + dFormat.format(createdDate) + ".");
out.println("Last modified by " + modifierName + " at " + dFormat.format(modifiedDate) + ".");
%>

HTH.

Cheers,
Paul
 

> -----Original Message-----
> From: opencms-dev-bounces at opencms.org 
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Marko Riedel
> Sent: 18. april 2011 16:49
> To: opencms-dev at opencms.org
> Subject: [opencms-dev] file modification time
> 
> 
> Hello there,
> 
> I am new to OpenCMS and I would like to know how to display 
> the modification time of a page at the bottom of the page. 
> E.g. if the page was last edited on the 15.4.11 then that's 
> the date I'd like to see. I guess this requires modification 
> of the relevant JSP template? Or can it be done with JavaScript?
> 
> I'd be grateful for any pointers you may have.
> 
> Best regards,
> 
> Marko Riedel
> 
> +---------------------------------------------------+
> | Marko Riedel, markoriedelde at yahoo.de              |
> | http://www.mathematik.uni-stuttgart.de/~riedelmo/ |
> +---------------------------------------------------+
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, 
> please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
> 


More information about the opencms-dev mailing list