Get help creating a program? UTC and Julian Date

Hello,

I wanted to know where I could get some help creating a widget.

I would like to be able to display UTC as well as Julian date.

I think I have a solution for getting the UTC by getting the offset and then adding or subtracting it to the seconds but I'm not sure if that would work
  • Yes. You should be able to get the current time and subtracting the timeZoneOffset from it, something like this...

    var moment = Time.now().add(new Time.Duration(-clockTime.timeZoneOffset));
    var info = Gregorian.info(moment, Time.FORMAT_SHORT);

    // info.hour
    // info.min
    // info.sec
    Sys.println(Lang.format("$1$:$2$:$3$", [
    info.hour,
    info.min.format("%02d"),
    info.sec.format("%02d")
    ]));


    Of course it might be simpler to just do the calculation yourself directly. This is pretty easy because the value held by a Time.Moment is the number of seconds since the 1970-01-01T00:00:00Z (it is in UTC time).

    var timestamp = Time.now().value();

    timestamp %= 86400;
    var hour = timestamp / 3600;
    var min = timestamp / 60 % 60;
    var sec = timestamp % 60;

    Sys.println(Lang.format("$1$:$2$:$3$", [
    hour,
    min.format("%02d"),
    sec.format("%02d")
    ]));


    If you are planning to support only ConnectIQ 2.x and newer devices, you could also use Gregorian.utcInfo(), but be wary that it won't be portable to older devices.

    Travis
  • ERROR: Undefined symbol "clockTime" detected.
    WARNING: Unable to detect scope 'Time.Duration' for the symbol 'initialize

    What would be causing this if I tried to use your time offset above for UTC?