java获取当前某个时间点

来源:互联网 发布:mac 管理员账户没有了 编辑:程序博客网 时间:2024/06/06 03:18
private String getTime(String flag, int times) {String time = new String();SimpleDateFormat startDf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");    SimpleDateFormat endDf = new SimpleDateFormat("yyyy-MM-dd 23:59:59");    Calendar cal=Calendar.getInstance();    if (times == 2) {    cal.add(Calendar.MONTH, -2);    //得到前两个月    } else if (times == 6) {    cal.add(Calendar.MONTH, -6);    //得到前六个月    } else {    cal.add(Calendar.MONTH, -1);    //得到前一个月    }               long l_date = cal.getTimeInMillis();        Date date=new Date(l_date);        if (flag.equals("start")) {        time = startDf.format(date);        } else {        time = endDf.format(new Date());        }        return time;}

0 0
原创粉丝点击