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
&quot;week&quot;, &quot;day&quot;, &quot;hour&quot;, &quot;minute&quot;, &quot;second&quot; or &quot;first&quot;.  The default is
&quot;second&quot;.</p>
</dd>
<dd>
<p>A $frac_part value of &quot;first&quot; is special and needs some more
explanation.  The time units will be considered in order from &quot;week&quot;
to &quot;second&quot;, 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 &quot;1h30m&quot;.  If the $duration
value is negative it is formatted like &quot;-1h30m&quot;.</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 &quot;PT1H30M&quot;.  If the $duration
value is negative it is formatter with a leading &quot;-&quot;, 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; &quot;1 hour and 30 minutes&quot;.  If the $duration value is
negative then the word &quot;negative&quot; 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 &quot;ago&quot; as long as $duration
is positive and the words &quot;from now&quot; if $duration is negative. A
$duration of 0 is special cased as &quot;just now&quot;.</p>
</dd>
</li>
<dt><strong><a name="item_dur_format_clock">$str = dur_format_clock( $duration )</a></strong>

<dd>
<p>Use stopwatch format; &quot;1:30:00&quot;, i.e. &quot;hhh:mm:ss&quot;.  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 &quot;-&quot;.  A value of <code>0</code> is formatted as &quot;0:00:00&quot;.</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 + -
显示快捷键?