Calendar

作者: 君养了只羊 | 来源:发表于2016-08-24 17:51 被阅读0次

    //获取当前时间

    Calendar calendar = Calendar.getInstance();

    //获取当前年

    int year = calendar.get(Calendar.YEAR);  

    //获取当前月份

    int month = calendar.get(Calendar.MONTH) + 1;

    //获取当前天

    int day = calendar.get(Calendar.DAY_OF_MONTH);

    //获取当前小时

    int hour = calendar.get(Calendar.HOUR_OF_DAY);

    //获取当前分钟

    int minute = calendar.get(Calendar.MINUTE);

    //获取是这周的第几天    周三 对应数字4

    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    //Calendar转Date

    Calendar calendar = Calendar.getInstance();

    Date date = calendar.getTime();

    // 获取前一天date

    private Date getBeforeDay(Date date) {

    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);

    calendar.add(Calendar.DAY_OF_MONTH, -1);

    date = calendar.getTime();

    return date;

    }

    // 获取后一天date

    private Date getNextDay(Date date) {

    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);

    calendar.add(Calendar.DAY_OF_MONTH, +1);

    date = calendar.getTime();

    return date;

    }

    相关文章

      网友评论

          本文标题:Calendar

          本文链接:https://www.haomeiwen.com/subject/osfosttx.html