Toybox.Time.Gregorian.utcInfo

Former Member
Former Member
I'm trying to use this function Toybox.Time.Gregorian.utcInfo and on the simulator it works fine, but when I copy the app to the watch I get an error saying that utcInfo is not defined.

Here is the code I have:

// get utc time
var utcTime = Toybox.Time.Gregorian.utcInfo(Time.now(), Calendar.FORMAT_MEDIUM);

Is there another way to get the current utc time?

I just recently updated to the 2.2.1 SDK
  • What watch are you using? Per the API doc, it's only available on watches with a 2.x.x VM:
    #utcInfo(date, format) ⇒ Info

    Use utcInfo() to retrieve a Gregorian.Info for a date converted to UTC.

    Parameters:
    date (Moment) — Moment object to get Info from
    format (Number) — Time FORMAT_XXX constant to use
    Returns:
    (Info) — For FORMAT_SHORT, all values in Info are integers. For FORMAT_MEDIUM and FORMAT_LONG, the month/day fields have the strings for the date in question. The time returned has been converted to UTC.
    Since:
    2.0.0


    As far as how else to get the info, you can to something like this for the time:
    var local=Sys.getClockTime();
    var o=local.timeZoneOffset;
    var d=local.dst;

    and use o and d to adjust the local time to utc.
  • Former Member
    Former Member over 8 years ago
    Thanks for pointing this out, i forgot to check the version info. This is on a Fenix 3 HR.

    I'll use yoru suggestion below.

    What watch are you using? Per the API doc, it's only available on watches with a 2.x.x VM:

    As far as how else to get the info, you can to something like this for the time:
    var local=Sys.getClockTime();
    var o=local.timeZoneOffset;
    var d=local.dst;

    and use o and d to adjust the local time to utc.