Time-based Load Rules come in handy when you want to load a Tag in a specific timezone. By default, the timezone is determined from the local time set in the visitor's browser, and not the server or visitor’s time/time zone. But if you want to override it with UTC time, you must convert the browser’s local time to the UTC format. This article walks you through the steps to do that.

This article assumes that you are familiar with Load Rules and how to set up Time-based load rules in particular.

Converting browser local time to UTC

  1. Import the following UTC date and time Variables to your Data Layer tab. The easiest way to do this is by using Tealium's Bulk Import tool.
    datetime_year_utc, "UDO Variable",, "Will output a number. ex: 2015"
    datetime_month_utc, "UDO Variable",, "Will output a number. ex: 5"
    datetime_day_utc, "UDO Variable",, "Will output a number. ex: 7"
    datetime_day_string_utc, "UDO Variable", "Will output a string. ex: Fri"
    datetime_hour_utc, "UDO Variable",, "Will output a number in military time. ex: 23"
    datetime_minute_utc, "UDO Variable",, "Will output a number. ex: 57"
    datetime_second_utc, "UDO Variable",, "Will output a number. ex: 7"
    datetime_epoch_utc, "UDO Variable",, "Will output a Unix timestamp. ex: 1431057424923"
    datetime_string_utc, "UDO Variable",, "Will output a string. ex: 2015-05-08 03:57:04 UTC"
  2. Add a new JavaScript Code Extension and scope it to Preloader.
  3. Copy and paste the following code in the editor. This code will capture the date and time from the visitor’s browser and convert it to UTC.
    (function(d,y,m,da,dn,h,mi,s,ep,padL,days){
      padL=function(str,len,char){
        return (new Array((len||1)+1).join(char||0)+(str||'')).slice(-(len||2))
      }
      window.utag_data=window.utag_data||{}
      days="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_");
      d=new Date();
      y=d.getUTCFullYear();
      m=d.getUTCMonth()+1;
      da=d.getUTCDate();
      dn=days[d.getUTCDay()];
      h=d.getUTCHours();
      mi=d.getUTCMinutes();
      s=d.getUTCSeconds();
      ep=d.getTime();
      utag_data.datetime_year_utc=y;
      utag_data.datetime_month_utc=m;
      utag_data.datetime_day_utc=da;
      utag_data.datetime_day_string_utc=dn;
      utag_data.datetime_hour_utc=h;
      utag_data.datetime_minute_utc=mi;
      utag_data.datetime_second_utc=s;
      utag_data.datetime_epoch_utc=ep;
      utag_data.datetime_string_utc=y+"-"+padL(m)+"-"+padL(da)+" "+padL(h)+":"+padL(mi)+":"+padL(s)+" UTC";
    })();
    
  4. Insert your new Time-based Load Rule condition(s) using the new UTC Variables you imported in step #1. Make sure you are selecting the date and time in the UTC format, not in your local timezone. 

    You can use online converter tools (like this one) to convert the timezone so you know what values to put into the Load Rule.