vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Time zone</title>
  5. <style type="text/css">
  6. body, html {
  7. font-family: sans-serif;
  8. max-width: 800px;
  9. }
  10. </style>
  11. <script src="../../../dist/vis.js"></script>
  12. <link href="../../../dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  13. </head>
  14. <body>
  15. <h1>Time zone</h1>
  16. <p>
  17. The following demo shows how to display items in local time (default), in UTC, or for a specific time zone offset. By configuring your own <code>moment</code> constructor, you can display items in the time zone that you want. All timelines have the same start and end date.
  18. </p>
  19. <h2>Local time</h2>
  20. <div id="local"></div>
  21. <h2>UTC</h2>
  22. <div id="utc"></div>
  23. <h2>UTC +08:00</h2>
  24. <div id="plus8"></div>
  25. <script type="text/javascript">
  26. // Create a DataSet (allows two way data-binding)
  27. var today = vis.moment(vis.moment.utc().format('YYYY-MM-DDT00:00:00.000Z'));
  28. var start = today.clone();
  29. var end = today.clone().add(2, 'day');
  30. var customTime = today.clone().add(28, 'hour');
  31. var items = new vis.DataSet([
  32. {id: 1, content: 'item 1', start: today.clone().add(8, 'hour')},
  33. {id: 2, content: 'item 2', start: today.clone().add(16, 'hour')},
  34. {id: 3, content: 'item 3', start: today.clone().add(32, 'hour')}
  35. ]);
  36. // Create a timeline displaying in local time (default)
  37. var timelineLocal = new vis.Timeline(document.getElementById('local'), items, {
  38. editable: true,
  39. start: start,
  40. end: end
  41. });
  42. timelineLocal.addCustomTime(customTime);
  43. // Create a timeline displaying in UTC
  44. var timelineUTC = new vis.Timeline(document.getElementById('utc'), items, {
  45. editable: true,
  46. start: start,
  47. end: end,
  48. moment: function (date) {
  49. return vis.moment(date).utc();
  50. }
  51. });
  52. timelineUTC.addCustomTime(customTime);
  53. // Create a timeline displaying in UTC +08:00
  54. var timelinePlus8 = new vis.Timeline(document.getElementById('plus8'), items, {
  55. editable: true,
  56. start: start,
  57. end: end,
  58. moment: function (date) {
  59. return vis.moment(date).utcOffset('+08:00');
  60. }
  61. });
  62. timelinePlus8.addCustomTime(customTime);
  63. </script>
  64. </body>
  65. </html>