<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>QLJ's Blog &#187; time</title>
	<atom:link href="http://qlj.sh.cn/tag/time/feed/" rel="self" type="application/rss+xml" />
	<link>http://qlj.sh.cn</link>
	<description>搜集网络信息,风云磅实验</description>
	<lastBuildDate>Thu, 26 Jan 2012 21:20:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>VB转UNIX_TIMESTAMP</title>
		<link>http://qlj.sh.cn/software/20100402/vb-unix_timestamp/</link>
		<comments>http://qlj.sh.cn/software/20100402/vb-unix_timestamp/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 06:00:05 +0000</pubDate>
		<dc:creator>qlj</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[VB]]></category>

		<guid isPermaLink="false">http://qlj.sh.cn/?p=1067</guid>
		<description><![CDATA[用PHP 一直是UNIX_TIMESTAMP存数据库的
但是VB没有这个


Option Explicit
Dim DateTime As String
&#160;
Public Function unixtime(ByVal DateTime As String)
&#160;
unixtime = DateDiff(&#34;s&#34;, &#34;01/1/1970 12:00:00 AM&#34;, DateTime)
End Function
'使用方法
Private Sub Command7_Click()
Textid.Text = unixtime(Now)
End Sub

再看下VB DateDiff函数
返回 Variant (Long) 的值，表示两个指定日期间的时间间隔数目。
语法
DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
DateDiff 函数语法中有下列命名参数：
部分 描述
interval 必要。字符串表达式，表示用来计算date1 和 date2 的时间差的时间间隔
Date1□date2 必要；Variant (Date)。计算中要用到的两个日期。
Firstdayofweek 可选。指定一个星期的第一天的常数。如果未予指定，则以星期日为第一天。
firstweekofyear 可选。指定一年的第一周的常数。如果未予指定，则以包含 1 月 1 日的星期为第一周。 
设置
interval 参数的设定值如下：
设置 描述
yyyy 年
q 季
m 月
y 一年的日数
d 日
w 一周的日数
ww 周
h [...]]]></description>
			<content:encoded><![CDATA[<p>用PHP 一直是UNIX_TIMESTAMP存数据库的<br />
但是VB没有这个<br />
<span id="more-1067"></span></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #000080;">Dim</span> DateTime <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
&nbsp;
<span style="color: #000080;">Public</span> <span style="color: #000080;">Function</span> unixtime(<span style="color: #000080;">ByVal</span> DateTime <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>)
&nbsp;
unixtime = DateDiff(<span style="color: #800000;">&quot;s&quot;</span>, <span style="color: #800000;">&quot;01/1/1970 12:00:00 AM&quot;</span>, DateTime)
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
<span style="color: #008000;">'使用方法
</span><span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Command7_Click()
Textid.Text = unixtime(Now)
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p>再看下VB DateDiff函数<br />
返回 Variant (Long) 的值，表示两个指定日期间的时间间隔数目。</p>
<p>语法</p>
<p>DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])</p>
<p>DateDiff 函数语法中有下列命名参数：</p>
<p>部分 描述<br />
interval 必要。字符串表达式，表示用来计算date1 和 date2 的时间差的时间间隔<br />
Date1□date2 必要；Variant (Date)。计算中要用到的两个日期。<br />
Firstdayofweek 可选。指定一个星期的第一天的常数。如果未予指定，则以星期日为第一天。<br />
firstweekofyear 可选。指定一年的第一周的常数。如果未予指定，则以包含 1 月 1 日的星期为第一周。 </p>
<p>设置</p>
<p>interval 参数的设定值如下：</p>
<p>设置 描述<br />
yyyy 年<br />
q 季<br />
m 月<br />
y 一年的日数<br />
d 日<br />
w 一周的日数<br />
ww 周<br />
h 时<br />
n 分钟<br />
s 秒 </p>
<p>firstdayofweek 参数的设定值如下：</p>
<p>常数 值 描述<br />
vbUseSystem 0 使用 NLS API 设置。<br />
vbSunday 1 星期日（缺省值）<br />
vbMonday 2 星期一<br />
vbTuesday 3 星期二<br />
vbWednesday 4 星期三<br />
vbThursday 5 星期四<br />
vbFriday 6 星期五<br />
vbSaturday 7 星期六 </p>
<p>常数 值 描述<br />
vbUseSystem 0 用 NLS API 设置。<br />
vbFirstJan1 1 从包含 1 月 1 日的星期开始（缺省值）。<br />
vbFirstFourDays 2 从第一个其大半个星期在新的一年的一周开始。<br />
vbFirstFullWeek 3 从第一个无跨年度的星期开始。 </p>
<p>说明</p>
<p>DateDiff 函数可用来决定两个日期之间所指定的时间间隔数目。例如，可以使用 DateDiff 来计算两个日期之间相隔几日，或计算从今天起到年底还有多少个星期。</p>
<p>为了计算 date1 与 date2 相差的日数，可以使用“一年的日数”(y) 或“日”(d)。当 interval 是“一周的日数”(w) 时，DateDiff 返回两日期间的周数。如果 date1 是星期一，DateDiff 计算到 date2 为止的星期一的个数。这个数包含 date2 但不包含 date1。不过，如果 interval 是“周”(ww)，则 DateDiff 函数返回两日期间的“日历周”数。由计算 date1 与 date2 之间星期日的个数而得。如果 date2 刚好是星期日，则 date2 也会被加进 DateDiff 的计数结果中；但不论 date1 是否为星期日，都不将它算进去。</p>
<p>如果 date1 比 date2 来得晚，则 DateDiff 函数的返回值为负数。</p>
<p>firstdayofweek 参数会影响使用时间间隔符号 “W” 或 “WW” 计算的结果。</p>
<p>如果 date1 或 date2 是日期文字，则指定的年份成为该日期的固定部分。但是，如果 date1 或 date2 用双引号 (&#8221; &#8220;) 括起来，且年份略而不提，则在每次计算表达式 date1 或 date2 时，当前年份都会插入到代码之中。这样就可以书写适用于不同年份的程序代码。</p>
<p>在计算 12 月 31 日和来年的 1 月 1 日的年份差时，DateDiff 返回 1 表示相差一个年份，虽然实际上只相差一天而已。</p>
]]></content:encoded>
			<wfw:commentRss>http://qlj.sh.cn/software/20100402/vb-unix_timestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>python time模块详解(转)</title>
		<link>http://qlj.sh.cn/python/20100402/python-time/</link>
		<comments>http://qlj.sh.cn/python/20100402/python-time/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 19:29:16 +0000</pubDate>
		<dc:creator>qlj</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://qlj.sh.cn/?p=1065</guid>
		<description><![CDATA[刚开始学习python
把相关的内容做上记号
python 的内嵌time模板翻译及说明
一、简介
  time模块提供各种操作时间的函数
  说明：一般有两种表示时间的方式:
       第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的
       第二种以数组的形式表示即(struct_time),共有九个元素，分别表示，同一个时间戳的struct_time会因为时区不同而不同

    year (four digits, e.g. 1998)
    month (1-12)
    day (1-31)
    hours (0-23)
    minutes (0-59)
    seconds (0-59)
  [...]]]></description>
			<content:encoded><![CDATA[<p>刚开始学习python<br />
把相关的内容做上记号</p>
<p>python 的内嵌time模板翻译及说明</p>
<p>一、简介</p>
<p>  time模块提供各种操作时间的函数<br />
  说明：一般有两种表示时间的方式:<br />
       第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的<br />
       第二种以数组的形式表示即(struct_time),共有九个元素，分别表示，同一个时间戳的struct_time会因为时区不同而不同<br />
<span id="more-1065"></span><br />
    year (four digits, e.g. 1998)<br />
    month (1-12)<br />
    day (1-31)<br />
    hours (0-23)<br />
    minutes (0-59)<br />
    seconds (0-59)<br />
    weekday (0-6, Monday is 0)<br />
    Julian day (day in the year, 1-366)<br />
    DST (Daylight Savings Time) flag (-1, 0 or 1) 是否是夏令时<br />
    If the DST flag is 0, the time is given in the regular time zone;<br />
    if it is 1, the time is given in the DST time zone;<br />
    if it is -1, mktime() should guess based on the date and time.</p>
<p>二、函数介绍<br />
1.asctime()<br />
  asctime([tuple]) -> string<br />
  将一个struct_time(默认为当时时间)，转换成字符串<br />
        Convert a time tuple to a string, e.g. &#8216;Sat Jun 06 16:26:11 1998&#8242;.<br />
        When the time tuple is not present, current time as returned by localtime()<br />
        is used.</p>
<p>2.clock()<br />
  clock() -> floating point number<br />
  该函数有两个功能，<br />
  在第一次调用的时候，返回的是程序运行的实际时间；<br />
  以第二次之后的调用，返回的是自第一次调用后,到这次调用的时间间隔</p>
<p>  示例：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">view plaincopy to clipboardprint<span style="color: #66cc66;">?</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>  
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:  
    <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>  
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;clock1:%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">time</span>.<span style="color: black;">clock</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>  
    <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>  
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;clock2:%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">time</span>.<span style="color: black;">clock</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>  
    <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>  
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;clock3:%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">time</span>.<span style="color: black;">clock</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>  输出：<br />
  clock1:3.35238137808e-006<br />
  clock2:1.00004944763<br />
  clock3:2.00012040636<br />
  其中第一个clock输出的是程序运行时间<br />
  第二、三个clock输出的都是与第一个clock的时间间隔</p>
<p>3.sleep(&#8230;)<br />
  sleep(seconds)<br />
  线程推迟指定的时间运行，经过测试，单位为秒，但是在帮助文档中有以下这样一句话，这关是看不懂<br />
  “The argument may be a floating point number for subsecond precision.”</p>
<p>4.ctime(&#8230;)<br />
  ctime(seconds) -> string<br />
  将一个时间戳(默认为当前时间)转换成一个时间字符串<br />
  例如：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #dc143c;">time</span>.<span style="color: black;">ctime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>  输出为：&#8217;Sat Mar 28 22:24:24 2009&#8242;</p>
<p>5.gmtime(&#8230;)<br />
  gmtime([seconds]) -> (tm_year, tm_mon, tm_day, tm_hour, tm_min,tm_sec, tm_wday, tm_yday, tm_isdst)<br />
  将一个时间戳转换成一个UTC时区(0时区)的struct_time，如果seconds参数未输入，则以当前时间为转换标准</p>
<p>6.localtime(&#8230;)<br />
  localtime([seconds]) -> (tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)<br />
  将一个时间戳转换成一个当前时区的struct_time，如果seconds参数未输入，则以当前时间为转换标准</p>
<p>7.mktime(&#8230;)<br />
  mktime(tuple) -> floating point number<br />
  将一个以struct_time转换为时间戳</p>
<p>8.strftime(&#8230;)<br />
  strftime(format[, tuple]) -> string<br />
  将指定的struct_time(默认为当前时间)，根据指定的格式化字符串输出<br />
  python中时间日期格式化符号：<br />
  %y 两位数的年份表示（00-99）<br />
  %Y 四位数的年份表示（000-9999）<br />
  %m 月份（01-12）<br />
  %d 月内中的一天（0-31）<br />
  %H 24小时制小时数（0-23）<br />
  %I 12小时制小时数（01-12）<br />
  %M 分钟数（00=59）<br />
  %S 秒（00-59）</p>
<p>  %a 本地简化星期名称<br />
  %A 本地完整星期名称<br />
  %b 本地简化的月份名称<br />
  %B 本地完整的月份名称<br />
  %c 本地相应的日期表示和时间表示<br />
  %j 年内的一天（001-366）<br />
  %p 本地A.M.或P.M.的等价符<br />
  %U 一年中的星期数（00-53）星期天为星期的开始<br />
  %w 星期（0-6），星期天为星期的开始<br />
  %W 一年中的星期数（00-53）星期一为星期的开始<br />
  %x 本地相应的日期表示<br />
  %X 本地相应的时间表示<br />
  %Z 当前时区的名称<br />
  %% %号本身 </p>
<p>9.strptime(&#8230;)<br />
  strptime(string, format) -> struct_time<br />
  将时间字符串根据指定的格式化符转换成数组形式的时间<br />
  例如：<br />
  2009-03-20 11:45:39  对应的格式化字符串为：%Y-%m-%d %H:%M:%S<br />
  Sat Mar 28 22:24:24 2009 对应的格式化字符串为：%a %b %d %H:%M:%S %Y</p>
<p>10.time(&#8230;)<br />
   time() -> floating point number<br />
   返回当前时间的时间戳</p>
<p>三、疑点<br />
1.夏令时<br />
  在struct_time中，夏令时好像没有用，例如<br />
  a = (2009, 6, 28, 23, 8, 34, 5, 87, 1)<br />
  b = (2009, 6, 28, 23, 8, 34, 5, 87, 0)<br />
  a和b分别表示的是夏令时和标准时间，它们之间转换为时间戳应该相关3600，但是转换后输出都为646585714.0</p>
<p>四、小应用<br />
1.python获取当前时间<br />
   time.time() 获取当前时间戳<br />
   time.localtime() 当前时间的struct_time形式<br />
   time.ctime() 当前时间的字符串形式</p>
<p>2.python格式化字符串<br />
  格式化成2009-03-20 11:45:39形式</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%Y-%m-%d %H:%M:%S&quot;</span>, <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>  格式化成Sat Mar 28 22:24:24 2009形式</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%a %b %d %H:%M:%S %Y&quot;</span>, <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>3.将格式字符串转换为时间戳</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  a = <span style="color: #483d8b;">&quot;Sat Mar 28 22:24:24 2009&quot;</span>
  b = <span style="color: #dc143c;">time</span>.<span style="color: black;">mktime</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: black;">strptime</span><span style="color: black;">&#40;</span>a,<span style="color: #483d8b;">&quot;%a %b %d %H:%M:%S %Y&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>转载自csdn</p>
]]></content:encoded>
			<wfw:commentRss>http://qlj.sh.cn/python/20100402/python-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP时间变成几秒前,几分前,几小时前,几天前SNS模式</title>
		<link>http://qlj.sh.cn/php/20100319/php-time-sns/</link>
		<comments>http://qlj.sh.cn/php/20100319/php-time-sns/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 15:54:05 +0000</pubDate>
		<dc:creator>qlj</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[sns]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://qlj.sh.cn/?p=1032</guid>
		<description><![CDATA[最近模仿UCHOME的DOING
我寸在MYSQL的时间都是unix时间。


function qtime&#40;$time&#41;&#123;
       $limit = time&#40;&#41; - $time;
&#160;
       if&#40;$limit&#60;60&#41;
       $time=&#34;{$limit}秒前&#34;;
       if&#40;$limit&#62;=60 &#38;&#38; $limit&#60;3600&#41;&#123;
            $i = floor&#40;$limit/60&#41;;
      [...]]]></description>
			<content:encoded><![CDATA[<p>最近模仿UCHOME的DOING<br />
我寸在MYSQL的时间都是unix时间。<br />
<span id="more-1032"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> qtime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span>
       <span style="color: #000088;">$time</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$limit}</span>秒前&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">&gt;=</span><span style="color: #cc66cc;">60</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$_i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">%</span><span style="color:#800080;">60</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_i</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$time</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$i}</span>分<span style="color: #006699; font-weight: bold;">{$s}</span>秒前&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
       <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">&gt;=</span><span style="color: #cc66cc;">3600</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$_h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">%</span><span style="color:#800080;">3600</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_h</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$time</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$h}</span>小时<span style="color: #006699; font-weight: bold;">{$i}</span>分前&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
       <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">&gt;=</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">&lt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$time</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$d}</span>天前&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">&gt;=</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$time</span><span style="color: #339933;">=</span><span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y年n月j日'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>使用方法：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'postdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>qtime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'postdate'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>另外分享网上其他的代码</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> time_tran<span style="color: #009900;">&#40;</span><span style="color: #000088;">$the_time</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$now_time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   <span style="color: #000088;">$now_time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$now_time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$show_time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$the_time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$dur</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$now_time</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$show_time</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$the_time</span><span style="color: #339933;">;</span> 
   <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$dur</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'秒前'</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'分钟前'</span><span style="color: #339933;">;</span> 
     <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">return</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'小时前'</span><span style="color: #339933;">;</span> 
      <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">259200</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//3天内</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dur</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'天前'</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$the_time</span><span style="color: #339933;">;</span> 
       <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>后来发现了个更简单的</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> format_date<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #339933;">,</span><span style="color: #000088;">$isShowDate</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$date</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$limit</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'秒钟之前'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$limit</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'分钟之前'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">3600</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$limit</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'小时之前'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">86400</span> and <span style="color: #000088;">$limit</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">259200</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'天之前'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">259200</span> and <span style="color: #000088;">$isShowDate</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i:s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://qlj.sh.cn/php/20100319/php-time-sns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

