duration.html
来自「perl教程」· HTML 代码 · 共 149 行
HTML
149 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>ActiveState::Duration - Format and parse time duration values</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>ActiveState::Duration - Format and parse time duration values</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>ActiveState::Duration - Format and parse time duration values</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">ActiveState::Duration</span> <span class="string">qw(ago_eng)</span><span class="operator">;</span>
<span class="keyword">print</span> <span class="string">"It is now "</span><span class="operator">,</span> <span class="variable">ago_eng</span><span class="operator">(</span><span class="keyword">time</span><span class="operator">),</span> <span class="string">" since time begun.\n"</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <code>ActiveState::Duration</code> module provides functions to format and
parse time duration values. Time is expressed as a number of weeks,
days, hours, minutes and seconds.</p>
<dl>
<dt><strong><a name="item_dur_format_xxx">$str = dur_format_XXX( $duration )</a></strong>
<dt><strong>$str = dur_format_XXX( $duration, $precision )</strong>
<dt><strong>$str = dur_format_XXX( $duration, $precision, $frac_part )</strong>
<dd>
<p>The <a href="#item_dur_format_xxx"><code>dur_format_XXX()</code></a> functions take a time $duration value (in
seconds) and format it as a readable string. This section describes
the common arguments supported by most of <a href="#item_dur_format_xxx"><code>dur_format_XXX()</code></a> functions.
The <code>XXX</code> in the function name selects which format it returns and is
described below.</p>
</dd>
<dd>
<p>The $precision argument specify how close the string much match the
duration value. The default is 0.05 which means that up to 5% off is
acceptable. Pass 0 as the $precision to request an exact result.</p>
</dd>
<dd>
<p>The $frac_part specify at which time unit formatting will start using
fractions to achieve the desired precision. It should be one of
"week", "day", "hour", "minute", "second" or "first". The default is
"second".</p>
</dd>
<dd>
<p>A $frac_part value of "first" is special and needs some more
explanation. The time units will be considered in order from "week"
to "second", and the first one longer than the $duration is used.</p>
</dd>
</li>
<dt><strong><a name="item_dur_format_sm">$str = dur_format_sm( @ARGS )</a></strong>
<dd>
<p>Use the Sendmail format which looks like "1h30m". If the $duration
value is negative it is formatted like "-1h30m".</p>
</dd>
</li>
<dt><strong><a name="item_dur_format_iso">$str = dur_format_iso( @ARGS )</a></strong>
<dd>
<p>Use the ISO 8601 format which looks like "PT1H30M". If the $duration
value is negative it is formatter with a leading "-", even though that
is not standards conforming.</p>
</dd>
</li>
<dt><strong><a name="item_dur_format_eng">$str = dur_format_eng( @ARGS )</a></strong>
<dd>
<p>Use plain English; "1 hour and 30 minutes". If the $duration value is
negative then the word "negative" is prepended to the string.</p>
</dd>
</li>
<dt><strong><a name="item_ago_eng">$str = ago_eng( @ARGS )</a></strong>
<dd>
<p>Same as <a href="#item_dur_format_eng"><code>dur_format_eng()</code></a> but adds the word "ago" as long as $duration
is positive and the words "from now" if $duration is negative. A
$duration of 0 is special cased as "just now".</p>
</dd>
</li>
<dt><strong><a name="item_dur_format_clock">$str = dur_format_clock( $duration )</a></strong>
<dd>
<p>Use stopwatch format; "1:30:00", i.e. "hhh:mm:ss". This function does
not take the $precision or $frac_part arguments yet and the $duration
is truncated to whole seconds. A negative $duration value will be
formated with a leading "-". A value of <code>0</code> is formatted as "0:00:00".</p>
</dd>
</li>
<dt><strong><a name="item_dur_parse">$duration = dur_parse( $str )</a></strong>
<dd>
<p>This function takes a string representing a duration value and return
it as number of seconds. All strings produced by any of the
<a href="#item_dur_format_xxx"><code>dur_format_XXX()</code></a> or the <a href="#item_ago_eng"><code>ago_eng()</code></a> functions can be parsed back to an
$duration value by dur_parse(). It returns <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> if it cannot
parse the $str for some reason.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright (C) 2003 ActiveState Corp. All rights reserved.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../Time/Duration.html">the Time::Duration manpage</a>, <a href="../../lib/ActiveState/StopWatch.html">the ActiveState::StopWatch manpage</a>, <a href="../../lib/ActiveState/Bytes.html">the ActiveState::Bytes manpage</a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?