0

Let's say that I have a table that looks like this:

<table>
  <tr>
    <td>UTC+1</td>
    <td>10:00</td>
    <td>12:00</td>
    <td>18:00</td>
    <td>23:00</td>
  </tr>
  <tr>
    <td>Monday</td>
    <td>A</td>
    <td>B</td>
    <td>C</td>
    <td>D</td>
  </tr>
  <tr>
    <td>Tuesday</td>
    <td>D</td>
    <td>C</td>
    <td>B</td>
    <td>A</td>
  </tr>
  <tr>
    <td>Wednesday</td>
    <td>E</td>
    <td>F</td>
    <td>G</td>
    <td>H</td>
  </tr>
</table>

The table is for UTC+1. Let's also say that I want to add a feature that allows me to see the table in my local time zone, for example UTC+8. That would obviously change the table completely. Could someone point me in the right direction and explain how I could achieve this? I guess I could solve this with 24 different tables, one table per time zone, but that's not optimal when needed to update something and if I have more than one table.

M A
  • 25
  • 5
  • 2
    Does this answer your question? [Getting the client's time zone (and offset) in JavaScript](https://stackoverflow.com/questions/1091372/getting-the-clients-time-zone-and-offset-in-javascript) – Liftoff Mar 08 '21 at 18:02
  • 1
    Why would it "change the table completely"? Wouldn't it just change the top row, where the times are displayed? – Heretic Monkey Mar 08 '21 at 18:03
  • @HereticMonkey No I don't think so, for example what happens to the last values in the table if they go over to the next day if my local time zone is UTC+8? It would not be 23:00 wednesday but 06:00 thursday instead? – M A Mar 08 '21 at 18:08
  • You've tagged it with `javascript`, and that's what you'll need. [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) (or a library, like `momentjs`) will be beneficial to convert times (also see proposed dupe above), and then you need some way to put that into the DOM. Personally, i'd also use a library for that. This makes it difficult for me to write a full answer, as the end product would depend a lot on made library choices, and i am too lazy to write this in vanilla JS. – ASDFGerte Mar 08 '21 at 18:09
  • Moment.js contains fairly solid UTC conversions https://momentjs.com/docs/#/parsing/utc/ -- something simply like `moment.parseZone('2016-05-03T22:15:01+02:00').local(true).format();` will get timezone offsets. Additionally, a lot of coding of the table is required -- are these dates or days of the week? Does the information contained also need offsets? – franklylately Mar 08 '21 at 18:56

0 Answers0