How to get the current date with Monkey c

Former Member
Former Member
In some threads I saw People using "Calendar.info(...)" but nothing like this can be found in the documentation.
What is the easiest way to show the date without deriving year, month and day from the timestamp ?
Thanks
  • That is from people using this "using" at the beginning of their code.

    using Toybox.Time.Gregorian as Calendar;

    and to use it:
    var now = Time.now();
    var time = Calendar.info(now, Time.FORMAT_SHORT);

    and to use the parts, something like this:
    str=hour.format("%d")+":"+time.min.format("%02d")+":"+time.sec.format("%02d")+AMPM;


    ("hour" in this code is time.hour, but adjusted for 12/24 hr mode, and ampm as "a" or "p" in 12 hr mode)
    Other parts of "time" when doing this are the day of week, date, month year and if you use FORMAT_MEDIUM, you'll get "May" instead of 5 for the month, for example.
  • Former Member
    Former Member over 9 years ago
    With the "using", everything makes sense now.
    Will try it right away.
    Thanks
    Uwe
  • Former Member
    Former Member over 5 years ago in reply to jim_m_58

    what adjustment is it for 12/24 hour mode? time.somethingelse? +AMPM doesnt work for me either. I see no documentation about a 12/24 hour mode and AMPM

  • Sys.getDeviceSettings().is24Hour

    if false:

    hour%12, and if hour is then 0, make it 12

    if the original hour>=12 it's PM