Date to string using localtime

Hi, Im trying to convert a date to string with timezone different from UTC

tz = "-03:00"

t = event.get("lastHeartbeat")
event.set("last_heartbeat_text", Time.at(t.to_f).localtime(tz))

and no matter what time is in lastHearbeat allways I get the following

1970-01-01T00:33:41.000Z

image

If I just left the variable on event set

event.set("last_heartbeat_text", t )

I get the following:

image

If I do

            t = event.get("@timestamp").to_s
            event.set("last_heartbeat_text", Time.at(t.to_f).localtime(tz))

then I get

"last_heartbeat_text" => 1970-01-01T00:33:41.000Z,

So I think the problem is that [lastHeartbeat] is a string, not a LogStash::Timestamp. Use a date filter to parse and overwrite it.

1 Like

Perheps this?

 date {
   match => [ "lastHeartbeat", "yyyy-MM-dd HH:mm:ss.SSS" ]
   timezone => "America/Detroit"
}
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.