nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Burgess <>
Subject Re: Get YYYY from java.sql.Timestamp (jython engine, ExecuteScript)
Date Thu, 22 Feb 2018 19:46:19 GMT

Instead of "import java.util Calendar" try "from java.util import
Calendar".  You have the right approach (using calendar) to get the
year, but always be aware of any timezone issues (are the input
timestamps UTC? If not you might need to make an adjustment to the
calendar for the timezone).


On Thu, Feb 22, 2018 at 7:17 AM, James McMahon <> wrote:
> Hello. I have a java.sql.Timestamp object in a python script being executed
> by the python engine of ExecuteScript. As has been explained to me, the
> underpinnings of this appears to be jython.
> I need to get YYYY, MM, and DD from this java.sql.Timestamp object, ,myDT.
> I've done research and discovered that the trick to doing this is to first
> take your timestamp object and put it into a Calendar object. Like this
> (credit StackOverflow,
> Calendar cal = Calendar.getInstance();
> cal.setTimeInMillis(myDT);
> return cal.get(Calendar.YEAR);
> In an effort to do this I must import the Calendar class. I tried this:
> import java.util.Calendar
> and it failed, and I tried this
> import Calendar
> and it failed.
> Error thrown by NiFi is this:
> org.apache.nifi.processor.exception.ProcessException:
> no viable alternative at input 'cal' in script at line number
> How do I get the year from my timestamp object in python code
> running in an ExecuteScript processor that employs jython?
> Thanks very much.

View raw message