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

获取时间字符串

时间:2016-06-17 15:33:19      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

静态方法

 public static String getDate() {
        Calendar ca = Calendar.getInstance();
        int year = ca.get(Calendar.YEAR);//获取年份
        int month = ca.get(Calendar.MONTH) + 1;//获取月份
        int day = ca.get(Calendar.DATE);//获取日
        int hour = ca.get(Calendar.HOUR_OF_DAY);//小时
        int minute = ca.get(Calendar.MINUTE);//分;
        int second = ca.get(Calendar.SECOND);//
        String time;
        if (minute < 10 && second < 10) {
            time = year + "-" + month + "-" + day + " " + hour + ":" + "0" + minute + ":" + "0" + second;
        } else if (minute < 10 && second >= 10) {
            time = year + "-" + month + "-" + day + " " + hour + ":" + "0" + minute + ":" + second;
        } else if (minute >= 10 && second < 10) {
            time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + "0" + second;
        } else {
            time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
        }
        return time;
    }

 

获取时间字符串

标签:

原文地址:http://www.cnblogs.com/storm47/p/5594138.html

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