Logstash: convert date string to timestamp in millisecond

Hello everyone,

I have a filed date where my date is in the following format: 2016-03-30T12:37:27.424709000Z and I would like to convert it in millisecond.

Do you how to do ? I didn't find a solution

Thank you for your help and your attention.

S

Perhaps you can use the mutate filter's gsub option to replace the last six digits with an empty string, i.e. \d{6}Z$ -> Z.

Hi Magnus,

Thank you for the info but how i am supposed to use that in order to get the date in milliseconds.

Did you look at the documentation of the mutate filter's gsub option?

Yes, I did :slight_smile: !
Actually, I finally found what i was looking for:
ruby {
code => "event['milli'] = 1000*Time.parse(event['[myDate]']).to_f"
}

1 Like

Oh, you wanted to convert the timestamp to milliseconds since the epoch? Then I misunderstood your question.

no problem :wink: !