java 获取系统时间

来源:互联网 发布:518抽奖软件注册码 编辑:程序博客网 时间:2024/06/05 15:20
java输出当前时间三种方法   
方法一:默认方式输出现在时间 

        System.out.println(new Date(System.currentTimeMillis()));


方法二:Date方式,输出现在时间 

        Date time = new Date(); 

        System.out.println(time);


方法三:SimpleDateFormat方式,按设定的格式输出现在时间  

        SimpleDateFormat sdf= new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss "); 

        System.out.println(sdf.format(nowTime));

方法四:日期对象的方式,输出现在时间

Calender c=Calendar.getInstance();//可以日期

int year=c.get(Calendar.TEAR);

int month=c.get(Calendar.MONTH);

int day=c.get(Calendar.DAY);

int hour=c.get(Calendar.HOUR);

int minute=c.get(Calendar.MINUTE);

int second=c.get(Calendar.SECOND);

System.out.println(year+"/"+month+"/"+day+"  "+hour+":"+minute+":"second);

第三种方式比较常用


字母日期或时间元素表示示例GEra 标志符TextADy Year1996; 96M 年中的月份 MonthJuly; Jul; 07w年中的周数Number27W月份中的周数Number2D年中的天数Number189d月份中的天数Number10F月份中的星期Number2E星期中的天数TextTuesday; TueaAm/pm 标记TextPMH一天中的小时数(0-23) Number 0k一天中的小时数(1-24)Number24Kam/pm 中的小时数(0-11)Number0h am/pm 中的小时数(1-12) Number12m 小时中的分钟数 Number30s 分钟中的秒数 Number55S 毫秒数 Number978z时区General time zonePacific Standard Time; PST; GMT-08:00Z时区RFC 822 time zone-0800

0 0