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

获取本机当前时间

时间:2014-08-12 10:16:34      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   文件   for   ar   div   时间   

应用中调用本地的时间,显示在屏幕上的时候,可以在配置文件中写入它进行调用;

/**
     * 获取当前时间
     * 
     * @return
     */
    public static String getCurTime() {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmm");
        String time = dateFormat.format(now);
        return time;
    }

    public static int getDay() {
        Calendar now = Calendar.getInstance();
        int day = now.get(Calendar.DAY_OF_MONTH);
        return day;
    }

    public static int getMonth() {
        Calendar now = Calendar.getInstance();
        int month = now.get(Calendar.MONTH);
        return month;
    }

    public static String getWeek() {
        Calendar now = Calendar.getInstance();
        int week = now.get(Calendar.DAY_OF_WEEK);
        String str_week = "";
        switch (week) {
        case 1:
            str_week = "星期日";
            break;
        case 2:
            str_week = "星期一";
            break;
        case 3:
            str_week = "星期二";
            break;
        case 4:
            str_week = "星期三";
            break;
        case 5:
            str_week = "星期四";
            break;
        case 6:
            str_week = "星期五";
            break;
        case 7:
            str_week = "星期六";
            break;
        default:
            break;
        }
        return str_week;
    }

 

获取本机当前时间,布布扣,bubuko.com

获取本机当前时间

标签:style   blog   color   文件   for   ar   div   时间   

原文地址:http://www.cnblogs.com/weixiong-wang/p/3906499.html

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