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())
);
Methods
-
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)
Parameters:
Name Type Argument Default Description formatstring The desired format where various time representations are prefixed with %.
timestampnumber <optional>
The JavaScript timestamp.
capitalizeboolean <optional>
false Upper case first letter in the return.
Returns:
string .The formatted date.
Example
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 callingdate.getHours()ordate.getUTCHours()we will calltime.get('Hours').Parameters:
Name Type Description unitHighcharts.TimeUnitValue dateDate Returns:
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.
Parameters:
Name Type Argument Default Description normalizedIntervalHighcharts.TimeNormalizedObject The interval in axis values (ms) and the count
minnumber <optional>
The minimum in axis values
maxnumber <optional>
The maximum in axis values
startOfWeeknumber <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 timestampnumber 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 yearnumber The year
monthnumber The month. Zero-based, so January is 0.
datenumber <optional>
1 The day of the month
hoursnumber <optional>
0 The hour of the day, 0-23.
minutesnumber <optional>
0 The minutes
secondsnumber <optional>
0 The seconds
Returns:
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 callingdate.setHours(0)ordate.setUTCHours(0)we will calltime.set('Hours', 0).Parameters:
Name Type Description unitHighcharts.TimeUnitValue dateDate valuenumber Returns:
number .The epoch milliseconds of the updated date