Barnabas Wolf
2003-02-02 22:32:56 UTC
What is the best way to create a JavaScript Date object from Java?
Rhino wraps java.util.Date's using NativeJavaObject; it does not
convert them to NativeDate. I am currently using a workaround in a
WrapFactory:
if (val instanceof java.util.Date) {
long time=((java.util.Date) val).getTime();
return cx.evaluateString(
scope, "new Date(" + time + ");",
"date conversion", 1, null)
}
Is there a better way to do this? (More efficient or more elegant
way?)
Is there a specific reason Rhino is not able to convert Dates into
native types, like it can with Numbers and Strings?
Thanks,
Barnabas
Rhino wraps java.util.Date's using NativeJavaObject; it does not
convert them to NativeDate. I am currently using a workaround in a
WrapFactory:
if (val instanceof java.util.Date) {
long time=((java.util.Date) val).getTime();
return cx.evaluateString(
scope, "new Date(" + time + ");",
"date conversion", 1, null)
}
Is there a better way to do this? (More efficient or more elegant
way?)
Is there a specific reason Rhino is not able to convert Dates into
native types, like it can with Numbers and Strings?
Thanks,
Barnabas