您的位置:首页 > 编程语言 > Java开发

java Calendar DateFormat 时间 日期 月份 格式化 第一天 最后一天

2012-11-21 17:30 946 查看
//格式化类,选择自己需要的格式化类 年月日

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

//日历类

Calendar calendar = Calendar.getInstance();

calendar.set(Calendar.DAY_OF_MONTH, 1);//当月的第一天

System.out.println(dateFormat.format(calendar.getTime()));

calendar.add(Calendar.MONTH, 1);//月份加1

calendar.set(Calendar.DAY_OF_MONTH, 0);//当月的最后一天,0就代表上个月的最后一天

System.out.println(dateFormat.format(calendar.getTime()));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐