Converting time to milliseconds

converting 00:00:00.013 in to milliseconds

I used to dissect to get values and having trouble calculating the values

dissect {
mapping => {
"ExecuteTime" => %{hour}:%{minute}:%{second}.%{millisecond}"
}
}
if [hour] and [minute] and [second] and [millisecond] {
ruby {
code => "event.get['timeInSeconds'] = event.get['hour']*3600+event.get['minute']*60+event.get['second']+event.get['millisecond']/1000"
}
}

thanks in advance can you help me converting data in milliseconds

You are missing a " in your dissect mapping, and you need to use event.get/set to get and add fields to the event.

    dissect {
        mapping => { "ExecuteTime" => "%{hour}:%{minute}:%{second}.%{millisecond}" }
    }
    if [hour] and [minute] and [second] and [millisecond] {
        ruby {
            code => "event.set( 'timeInSeconds', event.get('hour').to_i*3600 + event.get('minute').to_i*60 +
                                                event.get('second').to_i + event.get('millisecond').to_f/1000)"
        }
    }
1 Like

Thanks @Badger you saved my day

than

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