ava 获取时间Time为24小时制

按指定格式获取时间

import Java.util.*;
import java.text.*;
public class TestDate {
public static void main(String args[]) {
Date today=new Date();
SimpleDateFormat f=new SimpleDateFormat(“yyyy年MM月dd日 hh:mm:ss”);
String time=f.format(today);
System.out.println(time);
}
}
格式里的时如果用hh表示用12小时制,HH表示用24小时制。
用12小时制时即用hh:mm:ss格式,时间到11:59:59,12:00:00变成00:00:00显示
用24小时制时即用HH:mm:ss格式 ,时间到23:59:59,24:00:00变成00:00:00显示
年MM月 中的MM必须是大写,hh:mm:ss 中的mm必须为小写。
具体大小写意义参见下面的表格:

字母 日期或时间元素 表示 示例
G Era 标志符 Text AD
y Year 1996 ; 96
M 年中的月份 Month July ; Jul ; 07
w 年中的周数 Number 27
W 月份中的周数 Number 2
D 年中的天数 Number 189
d 月份中的天数 Number 10
F 月份中的星期 Number 2
E 星期中的天数 Text Tuesday ; Tue
a Am/pm 标记 Text PM
H 一天中的小时数(0-23) Number 0
k 一天中的小时数(1-24) Number 24
K am/pm 中的小时数(0-11) Number 0
h am/pm 中的小时数(1-12) Number 12
m 小时中的分钟数 Number 30
s 分钟中的秒数 Number 55
S 毫秒数 Number 978
z 时区 General time zone Pacific Standard Time ; PST ; GMT-08:00
Z 时区 RFC 822 time zone -0800
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章