<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Greetings,</p>
    <p>My Erlang installation, Erlang/OTP 19 [erts-8.1], has
      calendar:local_time/0 and os:system_time/0. Both are easier to
      remember/find than going through all of the erlang module. IMHO.</p>
    <p><br>
    </p>
    <p>bengt<br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 10/21/2016 11:21 AM, José Valim
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAGnRm4+Y3egPVAzOp=yB8xUzYQA_O=YzV8-JJ_EYoBGLb9ssng@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <div dir="ltr">Hello Joe,
        <div><br>
        </div>
        <div>erlang:localtime() will return the local time as a {date,
          time} tuple according to your OS clock. As you mentioned,
          erlang:system_time() is the POSIX time which is UTC (UTC-ish
          since POSIX time doesn't account for leap seconds).</div>
        <div><br>
        </div>
        <div>Also Erlang 19.1 has added support for second, millisecond,
          microsecond, etc as units. Previously they were seconds,
          milli_seconds, micro_seconds, etc which did not agree with the
          SI convention. Therefore I believe you are reading the
          documentation for the most recent Erlang version while using
          an older version. You could try the latest Erlang or use the
          now deprecated "seconds" and "micro_seconds" units instead of
          the correct "second" and "microsecond".</div>
        <div><br>
        </div>
        <div class="gmail_extra">
          <div>
            <div class="m_9212161373271107918gmail_signature"
              data-smartmail="gmail_signature">
              <div dir="ltr">
                <div>
                  <div><br>
                  </div>
                  <div><span style="font-size:13px">
                      <div><span
style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José
                            Valim</b></span></div>
                      <div><span
style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">
                          <div><span
                              style="font-family:verdana,sans-serif;font-size:x-small"><a
                                moz-do-not-send="true"
                                href="http://www.plataformatec.com.br/"
                                style="color:rgb(42,93,176)"
                                target="_blank">www.plataformatec.com.br</a></span></div>
                          <div><span
                              style="font-family:verdana,sans-serif;font-size:x-small">Skype:
                              jv.ptec</span></div>
                          <div><span
                              style="font-family:verdana,sans-serif;font-size:x-small">Founder
                              and Director of R&D</span></div>
                        </span></div>
                    </span></div>
                </div>
              </div>
            </div>
          </div>
          <br>
          <div class="gmail_quote">On Fri, Oct 21, 2016 at 4:30 AM, Joe
            Armstrong <span dir="ltr"><<a moz-do-not-send="true"
                href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">When is
              now?<br>
              <br>
              I want the raw uncorrected system time - I assume this is<br>
              <br>
                 erlang:system_time()<br>
              <br>
              Seems to return the raw system clock in nanosconds past
              Epoch<br>
              <br>
              I want to convert this to a printable local time that
              agrees with my<br>
              wristwatch (ie what the man on the Clapham omnibus might
              call the<br>
              time)<br>
              <br>
              So I'd like to convert this to<br>
              Year,Month,Day,Hour,Min,Sec,Fr<wbr>action of sec<br>
              <br>
              There seems to be no function to do this (strange since,<br>
              this seems to me to be a common thing one might want to
              do).<br>
              <br>
              In the old days I'd write:<br>
              <br>
              t1() -><br>
                  T1 = erlang:timestamp(),<br>
                  calendar:now_to_local_time(T1)<wbr>.<br>
              <br>
              This works fine:<br>
              <br>
               > t1:t1().<br>
                {{2016,10,21},{9,59,59}}<br>
              <br>
              After scratching my head and reading the manual pages<br>
              I ended up with this:<br>
              <br>
              t2() -><br>
                  T1 = erlang:system_time(),<br>
                  system_time_to_ymdhms(T1).<br>
              <br>
              system_time_to_ymdhms(T) -><br>
                  S = erlang:convert_time_unit(T, native, seconds),<br>
                  {Days, X} = calendar:seconds_to_daystime(S<wbr>),<br>
                  {Y,Month,Day} = calendar:gregorian_days_to_dat<wbr>e(Days),<br>
                  {{Y+1970,Month,Day}, X}.<br>
              <br>
              Now stunningly obvious - and wrong by 2 hours<br>
              (The erlang manual page is WRONG - it's seconds (plural)
              not second)<br>
              <br>
                 > t1:t1().<br>
                 {{2016,10,21},{10,18,32}}<br>
                 > t1:t2().<br>
                 {{2016,10,21},{8,18,34}}<br>
              <br>
              The erlang manual page also says<br>
              <br>
              QUOTE<br>
              The erlang:timestamp() BIF is equivalent to:<br>
              <br>
              timestamp() -><br>
                 ErlangSystemTime = erlang:system_time(microsecond<wbr>),<br>
                 MegaSecs = ErlangSystemTime div 1000000000000,<br>
                 Secs = ErlangSystemTime div 1000000 - MegaSecs*1000000,<br>
                 MicroSecs = ErlangSystemTime rem 1000000,<br>
                 {MegaSecs, Secs, MicroSecs}.<br>
              <br>
              <br>
              Which is totally incorrect since it crashes<br>
              <br>
              t3() -><br>
                  T1 = timestamp(),<br>
                  calendar:now_to_local_time(T1)<wbr>.<br>
              <br>
              timestamp() -><br>
                  ErlangSystemTime = erlang:system_time(microsecond<wbr>),<br>
                  MegaSecs = ErlangSystemTime div 1000000000000,<br>
                  Secs = ErlangSystemTime div 1000000 -
              MegaSecs*1000000,<br>
                  MicroSecs = ErlangSystemTime rem 1000000,<br>
                  {MegaSecs, Secs, MicroSecs}.<br>
              <br>
              > t1:t3().<br>
              ** exception error: bad argument<br>
                   in function  erlang:system_time/1<br>
                      called as erlang:system_time(microsecond<wbr>)<br>
                   in call from t1:timestamp/0 (t1.erl, line 26)<br>
                   in call from t1:t3/0 (t1.erl, line 22)<br>
              <br>
              At which point I'm flummoxed - the erlang manual page is
              totally wrong<br>
              in several places. The routines in calendar are not in
              phase with the<br>
              changes in time routine.<br>
              <br>
              And I still can't convert erlang:system_time() to my local
              time<br>
              since it's two hour wrong<br>
              <br>
              /Joe<br>
              ______________________________<wbr>_________________<br>
              erlang-questions mailing list<br>
              <a moz-do-not-send="true"
                href="mailto:erlang-questions@erlang.org"
                target="_blank">erlang-questions@erlang.org</a><br>
              <a moz-do-not-send="true"
                href="http://erlang.org/mailman/listinfo/erlang-questions"
                rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>