Timestamps, XPATH and Java
Novell Cool Solutions: Tip
By Perin Blanchard
Digg This -
Posted: 1 Mar 2006
A reader asked:
"I am trying to get a human-readable string of the date and time that I can add to other text and then insert into the description attr in eDir. I am getting an error that says:
Message: Code(-9131) Error in vnd.nds.stream: ... eDirectory/Publisher/Matching Rule#XmlData:47 : Error evaluating XPATH expression ... XPathEvaluationException: function call to 'jformat:parse' resulted in an error: 'java.text.ParseException: Unparseable date: "1126129825"'.
You want something along the lines of this:
<do-set-local-variable name="current-format"> <arg-string> <token-xpath expression="jformat:format(jformat:new('MM/dd/yyyy:HH.mm.ss'),jdate:new())"/> </arg-string> </do-set-local-variable>
The timestamp value is "roughly" equivalent to what you would get from "java.lang.System.currentTimeMillis()" or "java.util.Date.getTime()". So to format and use it, you would need to strip the stuff including and after the '#', multiply it by 1000, create a new Date instance, etc.
You could use something like the following:
jformat:format(jformat:new('MM/dd/yyyy:HH.mm.ss'),jdate:new(number(substring-before(@timestamp,'#')) * 1000))
Then you would need to put that code in the appropriate location.
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com