now() is going to use the Gateway's timezone, because that's where the script is executed. I suspect you'll need to get crafty with a transform for the binding where you adjust the time based on the session timezone (props.timeZoneId) before formatting it.
I'm actually out of the office until next week so I won't be able to supply a code example until then. In theory, you'll configure your binding to be an expression which contains onlynow(60000). In a transform of that binding, you'll need to use available date and time libraries to modify the incoming value based on the difference between the Gateway's timezone id (self.session.props.gateway.timezone.id), and that of the Session (self.session.props.timeZoneId) before finally either formatting this new value and returning it, or returning the modified value into yet another transform where you format it into the desired string pattern.
Sure. I recommend DateTimeFormatter.ofPattern(). But I would move the complexity to a project script module with a DateTimeFormatter instance with your preferred pattern saved as a top level variable. Like so, perhaps:
from java.time import ZoneId
from java.time.format import DateTimeFormatter
defaultFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm")
def zonedFormat(ts, zoneid, format=None):
formatter = defaultFormatter if format is None else DateTimeFormatter.ofPattern(format)
return ts.toInstant().atZone(ZoneId.of(zoneid)).format(formatter)
If that is a project script named zoneHelper, then your transform becomes just:
I strongly recommend you use a project library script as I showed. Imports and pattern creation are heavy-weight operations in jython that you don't want to be doing on every execution of the transform.