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.2 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. <script src="../../googleAnalytics.js"></script>
  14. </head>
  15. <body>
  16. <h1>Time zone</h1>
  17. <p>
  18. 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.
  19. </p>
  20. <h2>Local time</h2>
  21. <div id="local"></div>
  22. <h2>UTC</h2>
  23. <div id="utc"></div>
  24. <h2>UTC +08:00</h2>
  25. <div id="plus8"></div>
  26. <script type="text/javascript">
  27. // Create a DataSet (allows two way data-binding)
  28. var today = vis.moment(vis.moment.utc().format('YYYY-MM-DDT00:00:00.000Z'));
  29. var start = today.clone();
  30. var end = today.clone().add(2, 'day');
  31. var customTime = today.clone().add(28, 'hour');
  32. var items = new vis.DataSet([
  33. {id: 1, content: 'item 1', start: today.clone().add(8, 'hour')},
  34. {id: 2, content: 'item 2', start: today.clone().add(16, 'hour')},
  35. {id: 3, content: 'item 3', start: today.clone().add(32, 'hour')}
  36. ]);
  37. // Create a timeline displaying in local time (default)
  38. var timelineLocal = new vis.Timeline(document.getElementById('local'), items, {
  39. editable: true,
  40. start: start,
  41. end: end
  42. });
  43. timelineLocal.addCustomTime(customTime);
  44. // Create a timeline displaying in UTC
  45. var timelineUTC = new vis.Timeline(document.getElementById('utc'), items, {
  46. editable: true,
  47. start: start,
  48. end: end,
  49. moment: function (date) {
  50. return vis.moment(date).utc();
  51. }
  52. });
  53. timelineUTC.addCustomTime(customTime);
  54. // Create a timeline displaying in UTC +08:00
  55. var timelinePlus8 = new vis.Timeline(document.getElementById('plus8'), items, {
  56. editable: true,
  57. start: start,
  58. end: end,
  59. moment: function (date) {
  60. return vis.moment(date).utcOffset('+08:00');
  61. }
  62. });
  63. timelinePlus8.addCustomTime(customTime);
  64. </script>
  65. </body>
  66. </html>