首页 > 代码库 > 获取本机当前时间

获取本机当前时间

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

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