转:http://blog.csdn.net/mergerly/article/details/41597235
A.将日期转换为Unix时间戳
将当前时间以Unix时间戳表示:<ol class="linenums" style="margin: 0px; padding-left: 40px; border-collapse: collapse;"><li class="L0" style="list-style-type: decimal;"><span class="pln" style="margin-top: 0px;">date </span><span class="pun" style="color: rgb(102, 102, 0);">+%</span><span class="pln">s</span></li></ol>输出如下:
<span class="lit" style="color: rgb(0, 102, 102);">1361542433</span><span style="line-height: 1.5; font-family: 微软雅黑,Consolas,sans-serif,"Andale Mono WT","Andale Mono","Bitstream Vera Sans Mono","Nimbus Mono L",Monaco,"Courier New",monospace;"></span>转换指定日期为Unix时间戳:
<ol class="linenums" style="margin: 0px; padding-left: 40px; border-collapse: collapse;"><li class="L0" style="list-style-type: decimal;"><span class="pln" style="margin-top: 0px;">date </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln">d </span><span class="str" style="color: rgb(0, 136, 0);">'2013-2-22 22:14'</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">+%</span><span class="pln">s</span></li></ol>输出如下:
<span class="lit" style="color: rgb(0, 102, 102);">1361542440</span>B.将Unix时间戳转换为日期时间
不指定日期时间的格式:
<ol class="linenums" style="margin: 0px; padding-left: 40px; border-collapse: collapse;"><li class="L0" style="list-style-type: decimal;"><span class="pln" style="margin-top: 0px;">date </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln">d </span><span class="pun" style="color: rgb(102, 102, 0);">@</span><span class="lit" style="color: rgb(0, 102, 102);">1361542596</span></li></ol>输出如下:
<span class="typ" style="color: rgb(102, 0, 102);">Fri</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Feb</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">22</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">22</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="lit" style="color: rgb(0, 102, 102);">16</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="lit" style="color: rgb(0, 102, 102);">36</span><span class="pln"> CST </span><span class="lit" style="color: rgb(0, 102, 102);">2013</span>指定日期格式的转换:
<ol class="linenums" style="margin: 0px; padding-left: 40px; border-collapse: collapse;"><li class="L0" style="list-style-type: decimal;"><span class="pln" style="margin-top: 0px;">date </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln">d </span><span class="pun" style="color: rgb(102, 102, 0);">@</span><span class="lit" style="color: rgb(0, 102, 102);">1361542596</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="str" style="color: rgb(0, 136, 0);">"%Y-%m-%d %H:%M:%S"</span></li></ol>输出如下:
<span class="lit" style="color: rgb(0, 102, 102);">2013</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="lit" style="color: rgb(0, 102, 102);">02</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="lit" style="color: rgb(0, 102, 102);">22</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">22</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="lit" style="color: rgb(0, 102, 102);">16</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="lit" style="color: rgb(0, 102, 102);">36</span>