Converting date to UNIX time in Logstash
NickName:Anatoli Ask DateTime:2016-08-22T17:23:01

Converting date to UNIX time in Logstash

Is it possible to convert date from "2016-08-22T09:09:55.487Z" format to UNIX time in Logstash? I have seen the opposite operation, but nothing about it.

Copyright Notice:Content Author:「Anatoli」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39075736/converting-date-to-unix-time-in-logstash

Answers
baudsp 2016-08-23T13:27:24

First, you'll have to convert \"2016-08-22T09:09:55.487Z\" to a date object, with the date filter:\n(supposing that the field date contains a string representing a valid ISO8601 timestamp)\n\ndate {\n match => [\"date\", \"ISO8601\"]\n target => \"date_object\"\n}\n\n\nAt this point you'll have a field date_object containing a logstash timestamp. \nThis timestamp can be converted to its epoch equivalent with the to_i method.\nTo do this we'll have to use the ruby filter, which allow to execute ruby code as a filter.\n\nruby { \n code => set.event('date_epoch', event.get('date_object').to_i)\" \n} \n\n\nThen you'll have a field date_epoch, which will be a number representing the UNIX time.",


More about “Converting date to UNIX time in Logstash” related questions

Converting date to UNIX time in Logstash

Is it possible to convert date from "2016-08-22T09:09:55.487Z" format to UNIX time in Logstash? I have seen the opposite operation, but nothing about it.

Show Detail

Logstash parsing unix time in milliseconds since epoch

I am trying to match unix time in milliseconds since epoch in logstash/grok using the UNIX_MS pattern and I am getting : pattern %{UNIX_MS:timestamp} not defined The UNIX_MS is defined Logstas...

Show Detail

Converting this date format to Unix Time in PHP

I'm trying to convert a time format in the format below to a unix timestamp using PHP j n Y H:i:s Im trying to find a way to convert to a unix timestamp so it can be used in SQL databases. An e...

Show Detail

Converting unix timestamp to a .NET Date Time in javascript

I'm interfacing with an api and they use .NET so all of my time stamps need to conform to .NET's Date Time format which looks something like this /Date(1379142000000-0700)/ I would like to conv...

Show Detail

Logstash "UNIX" date format to Human Readable

I am using logstash to parse nagios logs. Currently I have the following in my filter. date{ locale => en match =>["nagios_epoch", "UNIX"] target => "nagios_time&qu

Show Detail

pyspark converting unix time to date

I am using the following code to convert a column of unix time values into dates in pyspark: transactions3=transactions2.withColumn('date', transactions2['time'].cast('date')) The column transact...

Show Detail

Logstash converting date to valid joda time (@timestamp)

Hope someone can help me out! I have a question about logstash. I grok the following date with succes: 26/Jun/2013:14:00:26 +0200 Next, I want this date to be used as the @timestamp of the event....

Show Detail

Store date of birth in database as UNIX time?

I want to store the date of birth as a UNIX timestamp in my database, because this keeps the database small and it speed up the queries. However, when converting the date of birth to a UNIX time u...

Show Detail

using date.js to combine date, time and convert to unix timestamp in javascript

I have two values var date = "2012-08-10"; var time = "10:10"; Then I do var dte = date + " " + time; and var dte = new Date(dte).getTime() / 1000; The bel

Show Detail

logstash convert time to date time

I am using logstash to push data from filebeat to elasticsearch. My data has time as hh:mm:ss a (05:21:34 AM). I want to add today's date to it. This is filter of logstash config filter{ grok{...

Show Detail