• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JavaCast ignoring type attribute

New Here ,
Nov 02, 2006 Nov 02, 2006

Copy link to clipboard

Copied

I have a vendor Java object that returns a long representation of a timestamp. Unfortunately for me, this long has to be multiplied by 1000 before it becomes the correct timestamp. Attempting to do so throws an error in MX 7 about integers, even though I'm casting everything to longs. Is there either a way to work around this, or a different way to get a timestamp from a long?

Error thrown:

Could not convert the value 1.162484964E12 to an integer because it cannot fit inside an integer.

Code:

lngStartTime = JavaCast("long", Request.varName.getStartTime());
lngStartTime = JavaCast("long", lngStartTime * JavaCast("long", 1000)); //error thrown here
dteStartTime = CreateObject("java", "java.sql.Timestamp");
dteStartTime.init(lngStartTime);
TOPICS
Advanced techniques

Views

511

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
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 02, 2006 Nov 02, 2006
ProphecyVI wrote:
> I have a vendor Java object that returns a long representation of a timestamp.
> Unfortunately for me, this long has to be multiplied by 1000 before it becomes

unix epoch offset, *seconds* since 1-1-1970.

> dteStartTime = CreateObject("java", "java.sql.Timestamp");
> dteStartTime.init(lngStartTime);

well if you don't care about the ms part of your date (and you really can't
since your java class is returning unix epoch):

<cfscript>
startDate=createDate(1970,1,1);
dt=da...

Votes

Translate

Translate
Explorer ,
Nov 02, 2006 Nov 02, 2006

Copy link to clipboard

Copied

JavaCast-long is buggy.
Without going into details, do the calculations on the Java-side, sorry, no better option, even if that means writing a small Java-class yourself.

Votes

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
community guidelines
LEGEND ,
Nov 02, 2006 Nov 02, 2006

Copy link to clipboard

Copied

ProphecyVI wrote:
> I have a vendor Java object that returns a long representation of a timestamp.
> Unfortunately for me, this long has to be multiplied by 1000 before it becomes

unix epoch offset, *seconds* since 1-1-1970.

> dteStartTime = CreateObject("java", "java.sql.Timestamp");
> dteStartTime.init(lngStartTime);

well if you don't care about the ms part of your date (and you really can't
since your java class is returning unix epoch):

<cfscript>
startDate=createDate(1970,1,1);
dt=dateAdd("s",unixEpoch,startDate);
</cfscript>

where unixEpoch is the value returned by your java class.

btw if you want to get the java epoch offset (ms since 1-1-1970) for a given date:

<cfscript>
t=now();
t=t.getTime();
</cfscript>

Votes

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
community guidelines
Explorer ,
Nov 02, 2006 Nov 02, 2006

Copy link to clipboard

Copied

LATEST
Thouroughly tested the JavaCast-long issue in the following article:
JavaCast : Useless long datatype

Can anyone confirm this?

Votes

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
community guidelines
Resources
Documentation