Skip to main content

Initialization

info

Download the DHTMLX Timepicker package as part of the DHTMLX Suite library.

Follow these steps to add DHTMLX Timepicker to an application:

<!DOCTYPE html>
<html>
<head>
<title>How to Start with DHTMLX TimePicker</title>
<script type="text/javascript" src="../../codebase/suite.js"></script>
<link rel="stylesheet" href="../../codebase/suite.css">
</head>
<body>
<div id="timepicker_container"></div>
<script>
// creating DHTMLX TimePicker
const timepicker = new dhx.Timepicker("timepicker_container", {
// config options
});
</script>
</body>
</html>

Include source files​

Unpack the downloaded package into your project folder.

Create an HTML file and add the full paths to the JS and CSS files of the DHTMLX Suite library in its header. The files are:

  • suite.js
  • suite.css
<script type="text/javascript" src="../../codebase/suite.js"></script>
<link rel="stylesheet" href="../../codebase/suite.css">

Create a container​

Add a container for Timepicker and give it an id, for example timepicker_container:

index.html
<div id="timepicker_container"></div>

Initialize Timepicker​

Initialize Timepicker with the dhx.Timepicker object constructor. The constructor takes two parameters:

  • The HTML container for Timepicker
  • An object with configuration properties (optional). If you omit this argument, Timepicker uses the default settings.
index.js
// creating DHTMLX TimePicker
const timepicker = new dhx.Timepicker("timepicker_container", {
// config options
});

Configuration properties​

The Timepicker API overview article describes the properties you can specify to adapt Timepicker to your needs.

Set the initial value (optional)​

You can set the initial value of Timepicker in the value configuration property:

const timepicker = new dhx.Timepicker("timepicker_container", {
controls: true,
css: "dhx_widget--bordered",
value: new Date,
});

To change the value after you initialize Timepicker, use the setValue() method:

// set the value as a string
timepicker.setValue("00:39");
// set the value as a Date object
timepicker.setValue(new Date('January 10, 2019 17:54:00'));
// set the value as an array
timepicker.setValue([6,20,"AM"]);

Example​