Jim,

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).

Regards,
Matt


On Thu, Feb 22, 2018 at 7:17 AM, James McMahon <jsmcmah...@gmail.com> 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,
> https://stackoverflow.com/questions/6262570/how-to-retrieve-day-month-and-year-from-timestamplong-format):
>
> 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.
>
>

Reply via email to