Scripted field getting 12 hours date time difference


I am trying to get difference between current date time and a field(date time).

Timezone for date formatting: UTC
Date format: MM/D/YYYY HH:mm:ss.SSS
Date with nanoseconds format: MMM D, YYYY @ HH:mm:ss.SSSSSSSSS

Scripted Field:
if(!doc['job_start_time'].empty) return new Date().getTime() / 1000 - doc['job_start_time'].value.millis / 1000

job_start_time: 09/17/2020 02:07:35.379

I have set Output format: Human Readable

Whenever I am trying to get the difference It's showing +12 hours.

What I am doing wrong here? Please guide.

Hi and welcome to our community

Might be a timezone issue, what's the offset of your timezone to UTC ?


Hi, Thanks for the quick response.

May I know where can I find Offset information.

I was interested in the timezone you're living, whether the offset to UTC is +12, thx

Oh right.
My timezone is India Standard Time ‎(UTC+5:30)‎.

How can I get it in UTC so I will get correct difference.

Hi matw, I am new to ELK, would appreciate if you please guide me on this?

Sure, sorry for the delay, so new Date().getTime() should return UTC. So I would check 2 things:

  1. Is the server where this is executed, Elasticsearch is running in the right timezone?
  2. Is the raw timestamp stored in the Elasticsearch record in UTC?

Pretty sure this is a timezone issue, so first you've to check, if all component's timezone is correct.


Strange behavior I have observed.
When running in day it's giving correct difference.

When I run at night, it gives 12 hours difference. I checked and all set UTC format.

I don't know where should I look next.

I'd suggest looking at the raw values of

to find out when it this wrong difference is calculated. you say it's

09/17/2020 02:07:35.379

could it be is using the 12 hour clock instead of the 24 hour clock? this is just a wild guess, if e.g. it's wrong 0-12 and right 12-24 ...

Thanks matw.
That solved. The problem was cause of 12 hour clock.
24 hour clock working good.

Happy I could help