Display local time from UTC time in label component in perspective

Hi,
I'm quering the UTC time from a named query and showing it on label component.

I have this binding on the label coponent but, it does not convert it into the local time.
Am I doing something wrong?

Rather than a format transform, have you tried using an expression transform with the getTimezoneOffset() expression?

You would need to turn the {value} into a date first though. I think you could use fromMillis()?

1 Like

This seems to work. This adds 30 mins more than actual time.
Is this the best way of doing this?

Okay, I understand why there is a 30 min offset. getTimezoneOffset() return value 5.5 in this case and addHours() rounds it up to 6.

But I can't figure out the right way to do this.

Why? Why not use an expression binding of now()?

My goal is to find the best method to display a timestamp from DB in local timezone in label component. Not really to display the current time.
This was just an example that I tried to use to show the situation.

Change your expression to addMinutes({value}, getTimezoneOffset({value}) * 60)

1 Like

But why? Are you trying to check the DB server clock is correct? It seems strange.

Ewwww! Kevin!

That will break around DST changes.

Also:

1 Like

The getTimezoneOffset function is DST aware. There’s a raw version that isn’t.

Right, but it can be a different value before and after the arithmetic. That the arithmetic yields a java.util.Date with the wrong underlying UTC instant is just begging for later trouble.

I’m not trying to do anything like that. I’m describing a case where timestamps are stored in UTC in the database, but need to be displayed in the local time zone in the UI (Perspective).

For example, a Products table stores product details along with a TimeCompleted timestamp in UTC. When showing a product’s details in Perspective, I want TimeCompleted to appear in the local time zone instead of UTC.

1 Like

Use the techniques involving java's ZonedDateTime that I linked.

1 Like