Highlighted

java.io.File.lastModified returns 0

LEGEND ,
Sep 03, 2020

Copy link to clipboard

Copied

Hello, all,

 

I'm working on some legacy code, and the original developer was manually setting a "last modified" date on documents he worked on.  I learned that there is a programmatic way of doing this, and I'm trying, but the value returned is 0.

 

<!--- I got this from Pete Freitag's blog. --->
<cfset thisFile = CreateObject("java","java.io.File") />
<cfset thisFile.init("" & cgi.script_name & "") />
<cfset lastMod = thisFile.lastModified() />
<cfset lastMod = DateFormat(DateAdd('s',lastMod,"January 1 1970 00:00:00"),"mmmm dd, yyyy") />

 

Last mod is reporting as January 1, 1970, which means that it's 0.  Please advise.

 

V/r,

 

^ _ ^

Well, I think I know why it didn't work.  But I found another way of doing it, that I will be using.

<cfset thisFilePath = getCurrentTemplatePath() />
<cfset lastMod = DateFormat(GetFileInfo(thisFilePath).lastmodified,'mmmm dd, yyyy') />

I was hoping to do this in application.cfc, just the once.  The above method has to be put on each page, but I'm okay with that.

 

V/r,

 

^ _ ^

TOPICS
Advanced techniques, Asynchronous, Builder, cfchart, Cffiddle, Connector, Database access, Documentation, Event gateways, Flash integration, Getting started, Monitoring, Reporting, Security, Server administration

Views

27

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

java.io.File.lastModified returns 0

LEGEND ,
Sep 03, 2020

Copy link to clipboard

Copied

Hello, all,

 

I'm working on some legacy code, and the original developer was manually setting a "last modified" date on documents he worked on.  I learned that there is a programmatic way of doing this, and I'm trying, but the value returned is 0.

 

<!--- I got this from Pete Freitag's blog. --->
<cfset thisFile = CreateObject("java","java.io.File") />
<cfset thisFile.init("" & cgi.script_name & "") />
<cfset lastMod = thisFile.lastModified() />
<cfset lastMod = DateFormat(DateAdd('s',lastMod,"January 1 1970 00:00:00"),"mmmm dd, yyyy") />

 

Last mod is reporting as January 1, 1970, which means that it's 0.  Please advise.

 

V/r,

 

^ _ ^

Well, I think I know why it didn't work.  But I found another way of doing it, that I will be using.

<cfset thisFilePath = getCurrentTemplatePath() />
<cfset lastMod = DateFormat(GetFileInfo(thisFilePath).lastmodified,'mmmm dd, yyyy') />

I was hoping to do this in application.cfc, just the once.  The above method has to be put on each page, but I'm okay with that.

 

V/r,

 

^ _ ^

TOPICS
Advanced techniques, Asynchronous, Builder, cfchart, Cffiddle, Connector, Database access, Documentation, Event gateways, Flash integration, Getting started, Monitoring, Reporting, Security, Server administration

Views

28

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 03, 2020 0
LEGEND ,
Sep 03, 2020

Copy link to clipboard

Copied

Well, I think I know why it didn't work.  But I found another way of doing it, that I will be using.

<cfset thisFilePath = getCurrentTemplatePath() />
<cfset lastMod = DateFormat(GetFileInfo(thisFilePath).lastmodified,'mmmm dd, yyyy') />

I was hoping to do this in application.cfc, just the once.  The above method has to be put on each page, but I'm okay with that.

 

V/r,

 

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 03, 2020 0