You'd be better compiling the java to a class file, it's failry easy.

I posted this for tony yesterday after a suggestion made by webguy,
should be a final version, nice and quick and lets you specify the
dates' format.

The formats are java and can be found at 

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Save the following as formatSecondsSinceEpoch.java ,compile it (javac
formatSecondsSinceEpoch.java) which should give you a
formatSecondsSinceEpoch.class file, stick this somewhere in CFMX's class
path and your'e good to go. You will of course need to download the JDK
from java.sun.com

-----------
import java.text.SimpleDateFormat;
import java.util.*;

public class formatSecondsSinceEpoch{
        String seconds;
        String format;
        public final String formatDate(String seconds, String format){
                long secs = Integer.parseInt(seconds);
                long millseconds = secs * 1000;
                Date dateObj = new Date(millseconds);
                SimpleDateFormat sdf = new SimpleDateFormat(format); //
                String formattedDate = sdf.format(dateObj);
                return formattedDate;
        }
}
-----------
<cfscript>
seconds = "1057580739";
format = "yyyy/MM/dd HH:mm:ss";
mydate =  createobject('java','formatSecondsSinceEpoch');
ret  = mydate.formatDate(seconds,format);
</cfscript>

<cfoutput>#ret#</cfoutput>

<cfloop from="1" to="500" index="i">
        <cfset seconds = seconds + 1>
        <cfset ret  =
mydate.formatDate(JavaCast("String",seconds),format)> <!--- Need to pass
in strings, so use JavaCast on the seconds if they are ints --->
        <cfoutput>#ret#</cfoutput><br>
</cfloop>
-----------

-----Original Message-----
From: Shahzad.Butt [mailto:[EMAIL PROTECTED] 
Sent: 08 July 2003 13:30
To: CF-Talk
Subject: RE: JSP/Java in CF Page


Default in Dreamweaver charset=iso-8859-1" I guess.

-----Original Message-----
From: webguy [mailto:[EMAIL PROTECTED] 
Sent: 08 July 2003 13:23
To: CF-Talk
Subject: RE: JSP/Java in CF Page


Looks like a unicode issue, what encoding are you using ?

WG

-----Original Message-----
From: Shahzad.Butt [mailto:[EMAIL PROTECTED]
Sent: 08 July 2003 13:10
To: CF-Talk
Subject: RE: JSP/Java in CF Page


Getting this error

"\u201cUTCDate," on line 9, column 31, is not a valid identifer name.
The CFML compiler was processing:

an expression beginning with "\u201cUTCDate.jsp\u201d", on line 9,
column 31.This message is usually caused by a problem in the expressions
structure. an expression beginning with "GetPageContext", on line 9,
column 6.This message is usually caused by a problem in the expressions
structure. a script statement beginning with "GetPageContext" on line 9,
column 6. a CFSCRIPT tag beginning on line 8, column 2.


The error occurred in C:\Test\UTC.cfm: line 9

7 : <body>
8 : <CFSCRIPT>
9 :      GetPageContext().include("UTCDate.jsp");
10 : </CFSCRIPT>



-----Original Message-----
From: webguy [mailto:[EMAIL PROTECTED]
Sent: 08 July 2003 11:46
To: CF-Talk
Subject: RE: JSP/Java in CF Page


<CFSCRIPT>
     GetPageContext().include("hello.jsp");
</CFSCRIPT>

Full details here...
http://www.macromedia.com/devnet/mx/coldfusion/articles/java.html

WG

-----Original Message-----
From: Shahzad.Butt [mailto:[EMAIL PROTECTED]
Sent: 08 July 2003 10:14
To: CF-Talk
Subject: JSP/Java in CF Page


Hi

First time writing Java/JSP code in CF. What should be the syntax to
include this java file in cf page and print results.

<%@ import java.text.SimpleDateFormat;%>
<%@ import java.util.*;%>
<% public class formatDate{
public static void main(String args[]) {
 String seconds = args[0];
 long secs = Integer.parseInt(1057580739);
 long millseconds = secs * 1000;
 Date dateObj = new Date(millseconds);
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String formattedDate = sdf.format(dateObj);
System.out.println(formattedDate);
}
}
%>


Shaz






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. 
http://www.fusionauthority.com/signup.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to