首页 > 其他 > 详细

获取本机当前时间

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

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

/**
     * 获取当前时间
     * 
     * @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

获取本机当前时间

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!