Force "getTimestamp" method to return UTC time

We have a module which streams alarm, tag history, and audit events to Kafka. For example on an alarm event we would send the timestamp like this:

String json = new JSONObject()
        .put("uuid", alarm.getId().toString())
        .put("gatewayName", this.hostName)
        .put("provider", provider)
        .put("tagPath", tagPath)
        .put("displayPath", path)
        .put("priority", alarm.getPriority().ordinal())
        .put("eventType", alarm.getState().ordinal())
        .put("eventData", String.valueOf(data.getRawValueMap()))
        .put("eventFlags", alarm.getLastEventState().ordinal())
        .put("epochms", data.getTimestamp())
        .toString();
SinkData toSend = new SinkData(alarmTopic, json, alarmSinkName);
sendKafkaData(toSend, false);

For “epochms” when this reaches Kafka, we can see it is the local timestamp, but since we have many locations in different time zones we want to unify to UTC.

Of course we can write a simple function to do the conversion, but I am wondering if there is some global setting we can set such that wherever we call “getTimestamp” it always returns the UTC time in millis.

Thanks,

Nick

They are UTC, but as soon as you turn it into a Date to view it you see it in the local timezone running that code.

What kind of object is data in your code snippet?

Data in the alarm event is this:

public void sendEquipmentAlarm(AlarmEvent alarm, EventData data, KafkaSettingsRecord kafkaSettings)

Data in tag history is this:

public void storeData(HistoricalData data)

Data in audit events is this:

public void sendAuditData(AuditRecord record)

I do see what you are talking about. I made this record from a machine on eastern time:

image

Then if I look at that timestamp on a machine in EST it shows EST:

If I look at the same timestamp in central time it shows central time:

So if I’m not mistaken here, if we want the millis timestamp to be in UTC,. there is nothing we need to do correct?

Thanks,

Nick

Yes, that's right.

1 Like