日期格式化分别得到年月日

来源:互联网 发布:淘宝直播的东西好吗 编辑:程序博客网 时间:2024/06/05 14:51

有时候想得到分别当前时间的年 ,月 日有一个笨一点的方法。


SimpleDateFormat先格式化在输出时间。



Date dt = new Date ();SimpleDateFormat month=new SimpleDateFormat("MM");SimpleDateFormat yearAll=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");SimpleDateFormat year=new SimpleDateFormat("yyyy");SimpleDateFormat day=new SimpleDateFormat("dd");SimpleDateFormat hours=new SimpleDateFormat("HH");SimpleDateFormat minute=new SimpleDateFormat("mm");System.out.println(month.format(dt));System.out.println(yearAll.format(dt));System.out.println(year.format(dt));System.out.println(hours.format(dt));System.out.println(minute.format(dt));

运行结果:


 072015-07-18 20:51:2820152051






0 0
原创粉丝点击