Forum Discussion

chintusasmal123's avatar
2 years ago
Solved

Deneb visual showing Germany Time

Hi Everyone, I'm using this Deneb visual code to display Clock but this clock show time based on my location which is IST but I want to show  time based on Germany's time. { "$schema": "https://...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi chintusasmal123 ,
    According to your description, you want to display the time on Deneb according to German time. First of all, by default now() gets the time based on the system's regional settings. To display the time according to the German time zone, first you need to get the current UTC date, right now Germany uses UTC+2 Daylight Saving Time, so you just need to add +2 to the hour of the UTC time you get. Here is the implementation code

    { 
    
      "$schema": "https://vega.github.io/schema/vega/v5.json", 
    
      "description": "A simple digital clock visualization showing the current date and time.", 
    
      "width": "container", 
    
      "height": "container", 
    
      "autosize": {"type": "fit", "contains": "padding"}, 
    
      "signals": [ 
    
        { 
    
          "name": "currentDate", 
    
          "init": "datetime(utcyear(now()), utcmonth(now()), utcdate(now()), utchours(now())+2, utcminutes(now()), utcseconds(now()))", 
    
          "on": [{"events": {"type": "timer", "throttle": 1000}, "update":"datetime(utcyear(now()), utcmonth(now()), utcdate(now()), utchours(now())+2, utcminutes(now()), utcseconds(now()))" }
          ] 
        }, 
    
        { 
    
          "name": "currentYear", 
    
          "init": "year(currentDate)", 
    
          "on": [ 
    
            { 
    
              "events": {"signal": "currentDate"}, 
    
              "update": "year(currentDate)" 
    
            } 
    
          ] 
    
        }, 
    
        { 
    
          "name": "currentMonth", 
    
          "init": "month(currentDate)+1", 
    
          "on": [ 
    
            { 
    
              "events": {"signal": "currentDate"}, 
    
              "update": "month(currentDate)+1" 
    
            } 
    
          ] 
    
        }, 
    
        { 
    
          "name": "currentDay", 
    
          "init": "date(currentDate)", 
    
          "on": [ 
    
            { 
    
              "events": {"signal": "currentDate"}, 
    
              "update": "date(currentDate)" 
    
            } 
    
          ] 
    
        }, 
    
        { 
    
          "name": "currentHour", 
    
          "init": "hours(currentDate)", 
    
          "on": [ 
    
            { 
    
              "events": {"signal": "currentDate"}, 
    
              "update": "hours(currentDate)" 
    
            } 
    
          ] 
    
        }, 
    
        { 
    
          "name": "currentMinute", 
    
          "init": "minutes(currentDate)", 
    
          "on": [ 
    
            { 
    
              "events": {"signal": "currentDate"}, 
    
              "update": "minutes(currentDate)" 
    
            } 
    
          ] 
    
        }, 
    
        { 
    
          "name": "currentSecond", 
    
          "init": "seconds(currentDate)", 
    
          "on": [ 
    
            {"events": {"signal": "currentDate"}, "update": "seconds(currentDate)"} 
    
          ] 
    
        }, 
    
        { 
    
          "name": "fontSize", 
    
          "value": 24, 
    
          "on": [ 
    
            { 
    
              "events": {"type": "resize"}, 
    
              "update": "min(width, height) / 20" 
    
            } 
    
          ] 
    
        } 
    
      ], 
    
      "marks": [ 
    
        { 
    
          "type": "text", 
    
          "encode": { 
    
            "enter": { 
    
              "x": {"signal": "width / 2"}, 
    
              "y": {"signal": "height / 2"}, 
    
              "align": {"value": "center"}, 
    
              "baseline": {"value": "middle"} 
    
            }, 
    
            "update": { 
    
              "text": { 
    
                "signal": "format(currentYear, '04') + '-' + format(currentMonth, '02') + '-' + format(currentDay, '02') + ' ' + format(currentHour, '02') + ':' + format(currentMinute, '02') + ':' + format(currentSecond, '02')" 
    
              }, 
    
              "fontSize": {"signal": "fontSize"} 
    
            } 
    
          } 
    
        } 
    
      ] 
    
    }

    Final output

     

    Best regards,
    Albert He

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly