使用SimpleDateFormat可以获取给定日期的年份、月份、日期和月份

来源:互联网 发布:qq群关系数据库 种子 编辑:程序博客网 时间:2024/05/23 09:57
Date date = new Date();SimpleDateFormat weekFormat = new SimpleDateFormat("E");System.out.println(weekFormat.format(date));SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM");System.out.println(monthFormat.format(date));SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");System.out.println(yearFormat.format(date));SimpleDateFormat dayFormat = new SimpleDateFormat("dd");System.out.println(dayFormat.format(date));

E代表星期,例如星期六。MMMM代表中文月份,如“六月”;MM代表月份,如“06”;


字母日期或时间元素表示示例GEra 标志符TextADy年Year199696M年中的月份MonthJulyJul07w年中的周数Number27W月份中的周数Number2D年中的天数Number189d月份中的天数Number10F月份中的星期Number2E星期中的天数TextTuesdayTueaAm/pm 标记TextPMH一天中的小时数(0-23)Number0k一天中的小时数(1-24)Number24Kam/pm 中的小时数(0-11)Number0ham/pm 中的小时数(1-12)Number12m小时中的分钟数Number30s分钟中的秒数Number55S毫秒数Number978z时区General time zonePacific Standard TimePSTGMT-08:00Z时区RFC 822 time zone-0800

SimpleDateFormat  API:
http://www.javaweb.cc/JavaAPI1.6/java/text/SimpleDateFormat.html

0 0
原创粉丝点击