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.

名字 类型 详情
options Highcharts.TimeOptions

Time options as defined in chart.options.time.

  • 6.0.5
// Apply time settings globally
    time: {
        timezone: 'Europe/London'

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

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


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

Formats a JavaScript date timestamp (milliseconds since Jan 1st 1970) into a human readable date string. The available format keys are listed below. Additional formats can be given in the Highcharts.dateFormats hook.

Supported format keys:

  • %a: Short weekday, like 'Mon'
  • %A: Long weekday, like 'Monday'
  • %d: Two digit day of the month, 01 to 31
  • %e: Day of the month, 1 through 31
  • %w: Day of the week, 0 through 6
  • %b: Short month, like 'Jan'
  • %B: Long month, like 'January'
  • %m: Two digit month number, 01 through 12
  • %y: Two digits year, like 09 for 2009
  • %Y: Four digits year, like 2009
  • %H: Two digits hours in 24h format, 00 through 23
  • %k: Hours in 24h format, 0 through 23
  • %I: Two digits hours in 12h format, 00 through 11
  • %l: Hours in 12h format, 1 through 12
  • %M: Two digits minutes, 00 through 59
  • %p: Upper case AM or PM
  • %P: Lower case AM or PM
  • %S: Two digits seconds, 00 through 59
  • %L: Milliseconds (naming from Ruby)
名字 类型 特质 默认值 详情
format string

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

timestamp number <可选>

The JavaScript timestamp.

capitalize boolean <可选>

Upper case first letter in the return.

string .

The formatted date.

const time = new Highcharts.Time();
const s = time.dateFormat('%Y-%m-%d %H:%M:%S', Date.UTC(2020, 0, 1));
console.log(s); // => 2020-01-01 00:00:00

get(unit, date)

Get the value of a date object in given units, and subject to the Time object's current timezone settings. This function corresponds directly to JavaScripts Date.getXXX / Date.getUTCXXX, so instead of calling date.getHours() or date.getUTCHours() we will call time.get('Hours').

名字 类型 详情
unit Highcharts.TimeUnitValue
date Date
number .

The given time unit

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.

名字 类型 特质 默认值 详情
normalizedInterval Highcharts.TimeNormalizedObject

The interval in axis values (ms) and the count

min number <可选>

The minimum in axis values

max number <可选>

The maximum in axis values

startOfWeek number <可选>


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

名字 类型 详情
timestamp number

The JavaScript timestamp to inspect.

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.

名字 类型 特质 默认值 详情
year number

The year

month number

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

date number <可选>

The day of the month

hours number <可选>

The hour of the day, 0-23.

minutes number <可选>

The minutes

seconds number <可选>

The seconds

number .

The time in milliseconds since January 1st 1970.

set(unit, date, value)

Set the value of a date object in given units, and subject to the Time object's current timezone settings. This function corresponds directly to JavaScripts Date.setXXX / Date.setUTCXXX, so instead of calling date.setHours(0) or date.setUTCHours(0) we will call time.set('Hours', 0).

名字 类型 详情
unit Highcharts.TimeUnitValue
date Date
value number
number .

The epoch milliseconds of the updated date