按指定格式获取时间
package com.primecredit; import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void main(String[] args) { System.out.println(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String date = sdf.format(new Date()); String date1 = sdf1.format(new Date()); System.out.println(date); System.out.println(date1); } } 格式里的时如果用hh表示用12小时制,HH表示用24小时制。MM必须是大写!-- 这样有点晕:
字母日期或时间元素表示示例GEra 标志符TextADy年Year1996 ; 96M年中的月份MonthJuly ; Jul ; 07w年中的周数Number27W月份中的周数Number2D年中的天数Number189d月份中的天数Number10F月份中的星期Number2E星期中的天数TextTuesday ; TueaAm/pm 标记TextPMH一天中的小时数(0-23)Number0k一天中的小时数(1-24)Number24Kam/pm 中的小时数(0-11)Number0ham/pm 中的小时数(1-12)Number12m小时中的分钟数Number30s分钟中的秒数Number55S毫秒数Number978z时区General time zonePacific Standard Time ; PST ; GMT-08:00Z时区RFC 822 time zone-0800