How to get time range

How can I get the time range of interface Granafa?
I’m trying to use the API with parameters time_from and time_till, so I need value the current date filter at the top right corner of interface.
Now, I take date from browser’s URL and transform into UNIX, but this is the wrong way. If you enter dasboard for the first time, the URL doesn’t have a time range.

I was able to find the solution to this task with angular:
var time_from = new Date(angular.element(‘grafana-app’).injector().get(‘timeSrv’).timeRange().from);
var time_till = new Date(angular.element(‘grafana-app’).injector().get(‘timeSrv’).timeRange().to);
format UNIX