Get gateway Time through scritping

Hi,
In Tag tree browser i am getting system time

But i want to capture the gateway time through scripting

how to get this ?

@PGriffith any method to do it?

system.date.now()

See system.date - Ignition User Manual 8.1 - Ignition Documentation.

no this is returning my system time only

we are using clinet timezoone

that why i am asking any alternative method capture the gateway time?

system.tag.readBlocking(['[System]Gateway/CurrentDateTime'])[0].value

we are showing system time in this tag
system.tag.readBlocking([’[System]Gateway/CurrentDateTime’])[0].value`

this is system time
image

this is gateway time

image

That tag is is gateway time. Is this more of a timezone question?

actually i am trying get the gateway time… that’s is the question

Is it off because of a timezone difference, or are the minutes and seconds off too?

If it’s a timezone thing, we can work around it. Otherwise you may have to call in to support.

Ok done

To be most explicit:
That time has the value of the gateway’s time, but is localized to the local timezone when you set the Vision timezone setting to Client, because in that case the Designer uses its own timezone information to format the string. The actual value of the tag is correct, it is just being localized for presentation.

Is there any way to get gateway time now?

That is the gateway time. I promise. The complication is that java.util.Date objects represent (basically) epoch time - an always increasing count of (milli)seconds since some epoch:
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Date.html

If you don’t believe me, try this code in the script console:

from java.text import DateFormat
from com.inductiveautomation.ignition.client.gateway_interface import GatewayConnectionManager
from java.util import TimeZone

formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)
tz = GatewayConnectionManager.getInstance().getGatewayTimeZone()
formatter.setTimeZone(tz)
gwTime = system.tag.readBlocking(["[System]Gateway/CurrentDateTime"])[0].value
formatter.format(gwTime)
formatter.setTimeZone(TimeZone.getTimeZone("Europe/Paris"))
formatter.format(gwTime)

My gateway (and designer) are in America/Los Angeles, yet I get the following output:

>>> 
u'February 18, 2022 at 9:34:38 AM PST'
u'February 18, 2022 at 6:34:38 PM CET'
3 Likes

You seem to misunderstand. Time in java is UTC. It is converted to local time zone when printed (or other string conversions). When you get any DateTime tag value, the UTC value is what travels through the network, not the string. If you need the string, you’ll want to use a message handler that will get and convert to string in the gateway, and return that string.

{ Edit: Paul beat me to it while distracted. So, what he said. }

1 Like

i am you believe you… i am just confused… thats why asked…when i just read the tag
gwTime = system.tag.readBlocking(["[System]Gateway/CurrentDateTime"])[0].value

i have got sytem time only

I don’t know about the script to get the gateway time that why asked how to get the time through scripting

now i am getting gateway time thanks a alot