Get current time

Former Member
Former Member
I'm trying to get the current time in a variable but its crashing my app

My code: var CurrentTime = getClockTime();

I need this as I'm using the System.Println to output to a text file and want to see when certain events happen?
  • You should start with examples:
    Garmin\SDK\connectiq-sdk-win-2.2.4\samples\Analog\source\

    In your code should be the class specified.
    Sys.getClockTime();

    Sys is shortcut for Toybox.System class name, so you should add to the head of the .mc file following string:
    using Toybox.System as Sys;
  • Given this in your .mc file:

    using Toybox.System as Sys;

    you want to use:

    var CurrentTime = Sys.getClockTime();
  • Former Member
    Former Member over 8 years ago
    Thanks!

    However when I do this I get "Obj" when I try to output this to a txt file.

    Example:

    System.println(xAccel + ","); //IL Get xAccel value
    System.println(yAccel + ","); //IL Get yAccel value
    System.println(zAccel + "," + "\n"); //IL Get zAccel value
    var CurrentTime = Sys.getClockTime();
    System.println(CurrentTime);


    On the last line of code I was expecting a time value but I get this: "-500,656,-531,Obj:"

    Do I need to explicitly convert the time value that is returned? in C Sharp I would use "ToString();" ?

    Thanks!
  • You need to get the "parts" and format it, as you don't get a string from the call. See the API documentation.

    So something like

    Sys.println(CurrentTime.hour.format("%d")+":"+CurrentTime.min.format("%02d"));
  • Former Member
    Former Member over 8 years ago
    Thanks!