码迷,mamicode.com
首页 > 其他好文 > 详细

new Date()当前日期格式

时间:2014-12-13 12:04:36      阅读:578      评论:0      收藏:0      [点我收藏+]

标签:ar   sp   on   bs   new   nbsp   res   br   ca   

 //取系统日期
    public String getDateWithString() {
        Calendar now = Calendar.getInstance();
        int month = now.get(Calendar.MONTH) + 1;         int day = now.get(Calendar.DAY_OF_MONTH);
        int year = now.get(Calendar.YEAR);
        String result = year + " 年 " + month + " 月 " + day + " 日 ";
        return result;
    }

    //取系统日期
    public String getDateWithYMD() {
        Calendar now = Calendar.getInstance();
        int month = now.get(Calendar.MONTH) + 1;
        int day = now.get(Calendar.DAY_OF_MONTH);
        int year = now.get(Calendar.YEAR);
        String date = year + "-" + month + "-" + day;
        return date;
    }

    //取系统日期
    public String getDateWithNum() {
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH) + 1;
        int day = now.get(Calendar.DAY_OF_MONTH);
        String smonth = "" + month;
        String sday = "" + day;
        if (month < 10) {
            smonth = "0" + month;
        }
        if (day < 10) {
            sday = "0" + day;
        }
        String date = year + smonth + sday;
        return date;
    }

    //取系统日期
    public Date getDate() {
        Calendar now = Calendar.getInstance();
        int month = now.get(Calendar.MONTH) + 1;
        int day = now.get(Calendar.DAY_OF_MONTH);
        int year = now.get(Calendar.YEAR);
        String date = year + "-" + month + "-" + day;
        Date result = Date.valueOf(date);
        return result;
    }

new Date()当前日期格式

标签:ar   sp   on   bs   new   nbsp   res   br   ca   

原文地址:http://www.cnblogs.com/qingshidaoren/p/4161074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!