Class: Time

Highcharts. Time

new Time(options)

The Time class. Time settings are applied in general for each page using Highcharts.setOptions, or individually for each Chart item through the time options set.

The Time object is available from Highcharts.Chart#time, which refers to Highcharts.time if no individual time settings are applied.

Parameters:
Name Type Description
options Highcharts.TimeOptions

Time options as defined in chart.options.time.

Since:
  • 6.0.5
Example
// Apply time settings globally
Highcharts.setOptions({
    time: {
        timezone: 'Europe/London'
    }
});

// Apply time settings by instance
var chart = Highcharts.chart('container', {
    time: {
        timezone: 'America/New_York'
    },
    series: [{
        data: [1, 4, 3, 5]
    }]
});

// Use the Time object
console.log(
       'Current time in New York',
       chart.time.dateFormat('%Y-%m-%d %H:%M:%S', Date.now())
);

Members

defaultOptions :number

The timezone offset in minutes. Positive values are west, negative values are east of UTC, as in the ECMAScript getTimezoneOffset method. Use this to display UTC based data in a predefined time zone.

Type:
  • number
Since:
  • 3.0.8
Default Value:
  • 0
See also:
Try it

Methods

dateFormat( [format], timestamp [, capitalize])

Formats a JavaScript date timestamp (milliseconds since Jan 1st 1970) into a human readable date string. The format is a subset of the formats for PHP's strftime function. Additional formats can be given in the Highcharts.dateFormats hook.

Parameters:
Name Type Argument Default Description
format string <optional>

The desired format where various time representations are prefixed with %.

timestamp number

The JavaScript timestamp.

capitalize boolean <optional>
false

Upper case first letter in the return.

Returns:
string .

The formatted date.

getTimeTicks(normalizedInterval [, min] [, max] [, startOfWeek])

Return an array with time positions distributed on round time values right and right after min and max. Used in datetime axes as well as for grouping data on a datetime axis.

Parameters:
Name Type Argument Default Description
normalizedInterval Highcharts.NormalizedIntervalObject

The interval in axis values (ms) and the count

min number <optional>

The minimum in axis values

max number <optional>

The maximum in axis values

startOfWeek number <optional>
1
Returns:

getTimezoneOffset(timestamp)

Get the time zone offset based on the current timezone information as set in the global options.

Parameters:
Name Type Description
timestamp number

The JavaScript timestamp to inspect.

Returns:
number .

The timezone offset in minutes compared to UTC.

makeTime(year, month [, date] [, hours] [, minutes] [, seconds])

Make a time and returns milliseconds. Interprets the inputs as UTC time, local time or a specific timezone time depending on the current time settings.

Parameters:
Name Type Argument Default Description
year number

The year

month number

The month. Zero-based, so January is 0.

date number <optional>
1

The day of the month

hours number <optional>
0

The hour of the day, 0-23.

minutes number <optional>
0

The minutes

seconds number <optional>
0

The seconds

Returns:
number .

The time in milliseconds since January 1st 1970.

resolveDTLFormat(f)

Resolve legacy formats of dateTimeLabelFormats (strings and arrays) into an object.

Parameters:
Name Type Description
f String | Array | Object

General format description

Returns:
Object .

The object definition