~ubuntu-branches/ubuntu/karmic/erlang/karmic-security

« back to all changes in this revision

Viewing changes to lib/kernel/doc/src/os.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-06-11 12:18:07 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090611121807-ks7eb4xrt7dsysgx
Tags: 1:13.b.1-dfsg-1
* New upstream release.
* Removed unnecessary dependency of erlang-os-mon on erlang-observer and
  erlang-tools and added missing dependency of erlang-nox on erlang-os-mon
  (closes: #529512).
* Removed a patch to eunit application because the bug was fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
      </desc>
135
135
    </func>
136
136
    <func>
 
137
      <name>timestamp() -> {MegaSecs, Secs, MicroSecs}</name>
 
138
      <fsummary>Returna a timestamp from the OS in the erlang:now/0 format</fsummary>
 
139
      <type>
 
140
        <v>MegaSecs = Secs = MicroSecs = int()</v>
 
141
      </type>
 
142
      <desc>
 
143
      <p>Returns a tuple in the same format as <seealso marker="erts:erlang#now/0">erlang:now/0</seealso>. The difference is that this function returns what the operating system thinks (a.k.a. the wall clock time) without any attemts at time correction. The result of two different calls to this function is <em>not</em> guaranteed to be different.</p>
 
144
      <p>The most obvious use for this function is logging. The tuple can be used together with the function <seealso marker="stdlib:calendar#now_to_universal_time/1">calendar:now_to_universal_time/1</seealso> 
 
145
or <seealso marker="stdlib:calendar#now_to_local_time/1">calendar:now_to_local_time/1</seealso> to get calendar time. Using the calendar time together with the <c>MicroSecs</c> part of the return tuple from this function allows you to log timestams in high resolution and consistent with the time in the rest of the operating system.</p>
 
146
      <p>Example of code formatting a string in the format &quot;DD Mon YYYY HH:MM:SS.mmmmmm&quot;, where DD is the day of month, Mon is the textual month name, YYYY is the year, HH:MM:SS is the time and mmmmmm is the microseconds in six positions:</p>
 
147
<code>
 
148
-module(print_time).
 
149
-export([format_utc_timestamp/0]).
 
150
format_utc_timestamp() ->
 
151
    TS = {_,_,Micro} = os:timestamp(),
 
152
    {{Year,Month,Day},{Hour,Minute,Second}} = 
 
153
        calendar:now_to_universal_time(TS),
 
154
    Mstr = element(Month,{"Jan","Feb","Mar","Apr","May","Jun","Jul",
 
155
                          "Aug","Sep","Oct","Nov","Dec"}),
 
156
    io_lib:format("~2w ~s ~4w ~2w:~2..0w:~2..0w.~6..0w",
 
157
                  [Day,Mstr,Year,Hour,Minute,Second,Micro]).
 
158
</code>
 
159
 
 
160
       <p>The module above could be used in the following way:</p>
 
161
<pre>
 
162
1> <input>io:format("~s~n",[print_time:format_utc_timestamp()]).</input>
 
163
29 Apr 2009  9:55:30.051711
 
164
</pre>
 
165
      </desc>
 
166
    </func>
 
167
    <func>
137
168
      <name>type() -> {Osfamily, Osname} | Osfamily</name>
138
169
      <fsummary>Return the OS family and, in some cases, OS name of the current operating system</fsummary>
139
170
      <type>