24小时制时间显示:

<span style="color: #000000;" twffan="done"><font face="新宋体&quot;><span style="color: #0000ff;" twffan="done">public</span> <span style="color: #0000ff;" twffan="done">class</span> Datetime <span style="color: #0000cc;" twffan="done">{</span><br /><br />    <span style="color: #0000ff;" twffan="done">public</span> <span style="color: #0000ff;" twffan="done">static</span> <span style="color: #0000ff;" twffan="done">void</span> main<span style="color: #0000cc;" twffan="done">(</span><span style="color: #ff0000;" twffan="done">String</span> args<span style="color: #0000cc;" twffan="done">[</span><span style="color: #0000cc;" twffan="done">]</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">{</span><br />         <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">util</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">Date</span> <span style="color: #ff0000;" twffan="done">current</span><span style="color: #0000cc;" twffan="done">=</span><span style="color: #0000ff;" twffan="done">new</span> <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">util</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">Date</span><span style="color: #0000cc;" twffan="done">(</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span><br />           <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">text</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">SimpleDateFormat</span> sdf<span style="color: #0000cc;" twffan="done">=</span><span style="color: #0000ff;" twffan="done">new</span> <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">text</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">SimpleDateFormat</span><span style="color: #0000cc;" twffan="done">(</span><span style="color: #ff00ff;" twffan="done">"yyyy-MM-dd HH:mm:ss"</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span> <br />           <span style="color: #ff0000;" twffan="done">String</span> c<span style="color: #0000cc;" twffan="done">=</span>sdf<span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">format</span><span style="color: #0000cc;" twffan="done">(</span><span style="color: #ff0000;" twffan="done">current</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span><br />           <span style="color: #ff0000;" twffan="done">System</span><span style="color: #0000cc;" twffan="done">.</span>out<span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">println</span><span style="color: #0000cc;" twffan="done">(</span>c<span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span><br />    <span style="color: #0000cc;" twffan="done">}</span><br /><span style="color: #0000cc;" twffan="done">}</span></font></span>

12小时制时间显示:

<span style="color: #000000;" twffan="done"><font face="新宋体&quot;><span style="color: #0000ff;" twffan="done">public</span> <span style="color: #0000ff;" twffan="done">class</span> Datetime <span style="color: #0000cc;" twffan="done">{</span><br /><br />    <span style="color: #0000ff;" twffan="done">public</span> <span style="color: #0000ff;" twffan="done">static</span> <span style="color: #0000ff;" twffan="done">void</span> main<span style="color: #0000cc;" twffan="done">(</span><span style="color: #ff0000;" twffan="done">String</span> args<span style="color: #0000cc;" twffan="done">[</span><span style="color: #0000cc;" twffan="done">]</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">{</span><br />         <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">util</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">Date</span> <span style="color: #ff0000;" twffan="done">current</span><span style="color: #0000cc;" twffan="done">=</span><span style="color: #0000ff;" twffan="done">new</span> <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">util</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">Date</span><span style="color: #0000cc;" twffan="done">(</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span><br />           <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">text</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">SimpleDateFormat</span> sdf<span style="color: #0000cc;" twffan="done">=</span><span style="color: #0000ff;" twffan="done">new</span> <span style="color: #ff0000;" twffan="done">java</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">text</span><span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">SimpleDateFormat</span><span style="color: #0000cc;" twffan="done">(</span><span style="color: #ff00ff;" twffan="done">"yyyy-MM-dd hh:mm:ss"</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span> <br />           <span style="color: #ff0000;" twffan="done">String</span> c<span style="color: #0000cc;" twffan="done">=</span>sdf<span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">format</span><span style="color: #0000cc;" twffan="done">(</span><span style="color: #ff0000;" twffan="done">current</span><span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span><br />           <span style="color: #ff0000;" twffan="done">System</span><span style="color: #0000cc;" twffan="done">.</span>out<span style="color: #0000cc;" twffan="done">.</span><span style="color: #ff0000;" twffan="done">println</span><span style="color: #0000cc;" twffan="done">(</span>c<span style="color: #0000cc;" twffan="done">)</span><span style="color: #0000cc;" twffan="done">;</span><br />    <span style="color: #0000cc;" twffan="done">}</span><br /><span style="color: #0000cc;" twffan="done">}</span></font></span>

<span style="color: #000000;" twffan="done"><font face="新宋体&quot;></font></span>

两者区别:yyyy-MM-dd HH:mm:ss ; yyyy-MM-dd hh:mm:ss

字母 日期或时间元素 表示 示例
<span style="font-family: NSimsun;" twffan="done">G</span> Era 标志符 Text <span style="font-family: NSimsun;" twffan="done">AD</span>
<span style="font-family: NSimsun;" twffan="done">y</span> Year <span style="font-family: NSimsun;" twffan="done">1996</span>; <span style="font-family: NSimsun;" twffan="done">96</span>
<span style="font-family: NSimsun;" twffan="done">M</span> 年中的月份 Month <span style="font-family: NSimsun;" twffan="done">July</span>; <span style="font-family: NSimsun;" twffan="done">Jul</span>; <span style="font-family: NSimsun;" twffan="done">07</span>
<span style="font-family: NSimsun;" twffan="done">w</span> 年中的周数 Number <span style="font-family: NSimsun;" twffan="done">27</span>
<span style="font-family: NSimsun;" twffan="done">W</span> 月份中的周数 Number <span style="font-family: NSimsun;" twffan="done">2</span>
<span style="font-family: NSimsun;" twffan="done">D</span> 年中的天数 Number <span style="font-family: NSimsun;" twffan="done">189</span>
<span style="font-family: NSimsun;" twffan="done">d</span> 月份中的天数 Number <span style="font-family: NSimsun;" twffan="done">10</span>
<span style="font-family: NSimsun;" twffan="done">F</span> 月份中的星期 Number <span style="font-family: NSimsun;" twffan="done">2</span>
<span style="font-family: NSimsun;" twffan="done">E</span> 星期中的天数 Text <span style="font-family: NSimsun;" twffan="done">Tuesday</span>; <span style="font-family: NSimsun;" twffan="done">Tue</span>
<span style="font-family: NSimsun;" twffan="done">a</span> Am/pm 标记 Text <span style="font-family: NSimsun;" twffan="done">PM</span>
<span style="font-family: NSimsun;" twffan="done">H</span> 一天中的小时数(0-23) Number <span style="font-family: NSimsun;" twffan="done">0</span>
<span style="font-family: NSimsun;" twffan="done">k</span> 一天中的小时数(1-24) Number <span style="font-family: NSimsun;" twffan="done">24</span>
<span style="font-family: NSimsun;" twffan="done">K</span> am/pm 中的小时数(0-11) Number <span style="font-family: NSimsun;" twffan="done">0</span>
<span style="font-family: NSimsun;" twffan="done">h</span> am/pm 中的小时数(1-12) Number <span style="font-family: NSimsun;" twffan="done">12</span>
<span style="font-family: NSimsun;" twffan="done">m</span> 小时中的分钟数 Number <span style="font-family: NSimsun;" twffan="done">30</span>
<span style="font-family: NSimsun;" twffan="done">s</span> 分钟中的秒数 Number <span style="font-family: NSimsun;" twffan="done">55</span>
<span style="font-family: NSimsun;" twffan="done">S</span> 毫秒数 Number <span style="font-family: NSimsun;" twffan="done">978</span>
<span style="font-family: NSimsun;" twffan="done">z</span> 时区 General time zone <span style="font-family: NSimsun;" twffan="done">Pacific Standard Time</span>; <span style="font-family: NSimsun;" twffan="done">PST</span>; <span style="font-family: NSimsun;" twffan="done">GMT-08:00</span>
<span style="font-family: NSimsun;" twffan="done">Z</span> 时区 RFC 822 time zone <span style="font-family: NSimsun;" twffan="done">-0800</span>

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注