eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Get time in IST format in currentDateIndicator

HI,

I am getting time in currentDateIndicator in UTC format how to convert to IST.
I am using xAxis: {
currentDateIndicator: true,
allowDecimals: false,
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Get time in IST format in currentDateIndicator

Hi there,

I think that the time.timezone property might be the one that you are looking for. Please take a look at it in the link below.
API Reference: https://api.highcharts.com/highcharts/time.timezone

Best regards!
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Get time in IST format in currentDateIndicator

HI kamil
i am looking https://www.highcharts.com/samples/gant ... cator/demo currentdateindicator only but I believe it shows time in UTC format how i can show it to IST format?
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Get time in IST format in currentDateIndicator

Could you write here as a reply how exactly would like to format your date?
Right now it is - Tue, Aug 02 2022, 10:10
So please rewrite how would you like it to look in your chart, and then I will come up with a solution.

Thank you!
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Get time in IST format in currentDateIndicator

right now its Tue, Aug 02 2022, 10:10 which is in UTC for me it should be Tue, Aug 02 2022, 3: 40 pm or 15: 40.

Convert UTC time to Indian Standard Time. IST Indian time zone offset is UTC+05:30.
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Get time in IST format in currentDateIndicator

As mentioned in a previous post, you can achieve it with the time.timezone property (with moment.js required).

Take a look at the demo below and tell me if that's what you wanted to achieve.

DEMO: https://jsfiddle.net/BlackLabel/nw2r84Ld/

Best regards!
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Get time in IST format in currentDateIndicator

yes this is exactly what i wanted but in my angular code it is not changing though its working in your code. in my package.json moment is there
"moment": "^2.29.3",

I am using inverted x axis gantt chart
Last edited by eraka on Tue Aug 02, 2022 12:45 pm, edited 1 time in total.
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Get time in IST format in currentDateIndicator

Have you included the timezone module in your imports? It is mandatory to have it, to get the timezone functionality to work.
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Get time in IST format in currentDateIndicator

moment timezone is there still it is not taking
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Get time in IST format in currentDateIndicator

It started appearing after i added
import * as moment_timezone from "moment-timezone";
(window as any).moment = moment_timezone;


but earlier it was 00:00 to 23:59 on x axis which was desirable but now its showing for next day date as well, plz see attachment
Attachments
fal.JPG
fal.JPG (12.49 KiB) Viewed 1364 times
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Get time in IST format in currentDateIndicator

To achieve what you need, you have to play around with the timestamps and timezones. The demo below should work in your timezone correctly, but to make it work in other timezones, please read more about the Date object in JavaScript (more specifically about timezones).

DEMO: https://jsfiddle.net/BlackLabel/sLj71rnc/
MDN: https://developer.mozilla.org/en-US/doc ... jects/Date
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Get time in IST format in currentDateIndicator

I am using max like this Date.UTC(
this.t1.getFullYear(),
this.t1.getMonth(),
this.t1.getDate(),
24
),

and min like
Date.UTC(
this.t1.getFullYear(),
this.t1.getMonth(),
this.t1.getDate(),
0,
0
),

in x axis
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Get time in IST format in currentDateIndicator

Date.UTC() and new Date return different values. Compare the demos I've sent you and adjust your max calculation. You can read more about it in the MDN link above.
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Get time in IST format in currentDateIndicator

thanks a lot!! i got the difference....
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Get time in IST format in currentDateIndicator

You're welcome! I'm glad that it's working for you now.

Best regards!
Kamil Musiałowski
Highcharts Developer

Return to “Highcharts Gantt”