- 浏览: 578556 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (411)
- webservice (3)
- oracle (37)
- sqlserver (8)
- j2ee (56)
- linux (7)
- javaweb (47)
- office (1)
- struts (23)
- hibernate (11)
- spring (29)
- 网络 (2)
- tomcat (13)
- tongweb (0)
- weblogic (0)
- powerdesiginer (3)
- svn (3)
- js (20)
- ie (2)
- 编译 (3)
- css (2)
- 操作系统 (5)
- Android (41)
- jbpm4.3 (1)
- fckeditor (3)
- 操作excel (2)
- db2常用命令 (1)
- ibatis (5)
- mysql (16)
- 表达式语言 (1)
- java方式调用存储过程 (1)
- ca (1)
- linux客户端 (1)
- 电子数码 (1)
- 行业应用 (12)
- 开发工具 (4)
- 面试 (1)
- 计算机原理 (1)
- NOSQL (5)
- 虚拟机 (1)
- nginx (0)
- velocity (2)
- jndi (1)
- spring mvc (39)
- springmvc (32)
- 安全 (5)
- htmleditor (6)
- iphone4 (1)
- html (4)
- jstl (2)
- ckeditor (5)
- 连接池 (1)
- jquery (6)
- 分页 (1)
- 技术研发规则 (1)
- javamail (1)
- maven (2)
- upload (1)
- log (1)
- 测试 (10)
- spring roo (1)
- 版本控制 (2)
- find bugs (0)
- jsf (0)
- springroo (0)
- 小道理 (1)
- 小道理,技术标准 (1)
- jsf (0)
- bitbao (2)
- redmine (3)
- 团队意识 (1)
- mybatis (2)
- jquery mobile (1)
- flexpaper (0)
- json (4)
- URLRewriteFilte (1)
- html5 (1)
- 都乐保活动 (0)
- openfire (0)
- TreeMap (1)
- build (0)
- javaweb,tag (0)
- algorithm (1)
- tag (2)
- 扯淡 (0)
- mac (2)
- 叶一火(老一) (1)
- 游玩 (1)
- 编码 (1)
- 上线部署 (0)
- 研发管理 (0)
- thumbnailator (2)
- 旅游 (0)
- bingweibo (1)
- 杂谈 (4)
- ktv (1)
- weibo (1)
- 爱情 (2)
- 饮食 (1)
- MediaWiki (1)
- git (1)
- 版本库 (1)
- servlet (1)
- 感悟 (1)
- 人生 (1)
- highcharts (1)
- poi (0)
- websphere (0)
- php (1)
最新评论
-
woshixushigang:
good
org.springframework.beans.TypeMismatchException: Failed to convert property valu -
nathanleewei:
org.springframework.jdbc.core.B ...
org.springframework.beans.TypeMismatchException: Failed to convert property valu -
浪禾木:
请问是ckeditor\contents.css吗?改过以后 ...
ckeditor自动换行问题 -
simusuishi:
刚哥威武!
ckeditor取值赋值问题 -
a455642158:
收割完毕……
Android开源项目源码下载(不断更新中)
package com.gist.report.chart.show;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Iterator;
public class TT {
//按日分割时间段
public static List<String> getTimeWeaveByDay(Date minDate, Date maxDate){
List<String> list = new ArrayList<String>();
Calendar minc = Calendar.getInstance();
Calendar maxc = Calendar.getInstance();
minc.setTime(minDate);
maxc.setTime(maxDate);
list.add(minc.get(Calendar.DATE)+"/"+(minc.get(Calendar.MONTH)+1)+"/"+minc.get(Calendar.YEAR)+"");
minc.add(Calendar.DATE, 1);
while(minc.before(maxc)){
list.add(minc.get(Calendar.DATE)+"/"+(minc.get(Calendar.MONTH)+1)+"/"+minc.get(Calendar.YEAR)+"");
minc.add(Calendar.DATE, 1);
}
list.add(minc.get(Calendar.DATE)+"/"+(minc.get(Calendar.MONTH)+1)+"/"+minc.get(Calendar.YEAR)+"");
return list;
}
//按月分割时间段
public static List<String> getTimeWeaveByMonth(Date minDate, Date maxDate){
List<String> list = new ArrayList<String>();
Calendar minc = Calendar.getInstance();
Calendar maxc = Calendar.getInstance();
minc.setTime(minDate);
maxc.setTime(maxDate);
list.add((minc.get(Calendar.MONTH)+1)+"/"+minc.get(Calendar.YEAR)+"");
minc.add(Calendar.MONTH, 1);
while(minc.before(maxc)){
list.add((minc.get(Calendar.MONTH)+1)+"/"+minc.get(Calendar.YEAR)+"");
minc.add(Calendar.MONTH, 1);
}
list.add((minc.get(Calendar.MONTH)+1)+"/"+minc.get(Calendar.YEAR)+"");
return list;
}
//按年分割时间段
public static List<String> getTimeWeaveByYear(Date minDate, Date maxDate){
int splitValue = 0;
List<String> list = new ArrayList<String>();
Calendar minc = Calendar.getInstance();
Calendar maxc = Calendar.getInstance();
minc.setTime(minDate);
maxc.setTime(maxDate);
list.add(minc.get(Calendar.YEAR)+"");
minc.add(Calendar.YEAR, 1);
while(minc.before(maxc)){
list.add(minc.get(Calendar.YEAR)+"");
minc.add(Calendar.YEAR, 1);
}
list.add(minc.get(Calendar.YEAR)+"");
return list;
}
//格式化日期
public static List<String> formatDate(List<String> dates){
List<String> list = new ArrayList<String>();
list.addAll(dates);
for(int i=0; i<list.size(); i++){
String [] s = list.get(i).split("/");
if(s.length == 1){
list.set(i, "01/01/"+s[0]);
}else if(s.length == 2){
list.set(i, "01/"+s[0]+"/"+s[1]);
}
}
return list;
}
//获得起始日期
public static Map<String,String[]> getStartEndGroup(List<String> dates){
// TreeMap<String, String[]> map = new TreeMap<String, String[]>(new Comparator<String>(){
//
// @Override
// public int compare(String o1, String o2) {
// // TODO Auto-generated method stub
// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
// Date d1 = null;
// Date d2 = null;
// try {
// d1 = sdf.parse(o1);
// d2 = sdf.parse(o2);
// } catch (ParseException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// if(d1.after(d2)){
// return 1;
// }
// return 0;
// }
// });
Map<String, String[]> map = new TreeMap<String, String[]>();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date d = null;
String [] startAndEnd = new String [2];
List<String> list = new ArrayList<String>();
List<String> cloneList = new ArrayList<String>();
List<String> years = new ArrayList<String>();
List<String> months = new ArrayList<String>();
cloneList.addAll(dates);
for(int i=0; i<cloneList.size(); i++){
String [] s = cloneList.get(i).split("/");
if(!years.contains(s[2])){
years.add(s[2]);
}
if(!months.contains(s[1])){
months.add(s[1]);
}
}
if(years.size()>1){//按年
for(String year : years){
for(int i=0; i<cloneList.size(); i++){
String [] s = cloneList.get(i).split("/");
try {
d = sdf.parse(cloneList.get(i));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(year.equals(s[2])){
map.put(cloneList.get(i), getStartAndEnd(d,"year"));
}
}
}
}else if(months.size()>1){//按月
for(String month : months){
for(int i=0; i<cloneList.size(); i++){
String [] s = cloneList.get(i).split("/");
try {
d = sdf.parse(cloneList.get(i));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(month.equals(s[1])){
map.put(cloneList.get(i), getStartAndEnd(d,"month"));
}
}
}
}else{ //按日
for(int i=0; i<cloneList.size(); i++){
String [] s = cloneList.get(i).split("/");
map.put(cloneList.get(i), new String[]{cloneList.get(i),cloneList.get(i)});
}
}
// Set set = map.entrySet();
// java.util.Map.Entry entries[] = (java.util.Map.Entry[])set.toArray(new java.util.Map.Entry[set.size()]);
// Arrays.sort(entries, new Comparator() {
// public int compare(Object arg0, Object arg1){
// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
// Date d1 = null;
// Date d2 = null;
// try {
//
// String s1 = ((Map.Entry)arg0).getKey().toString();
// String s2 = ((Map.Entry)arg1).getKey().toString();
// System.out.println(s1+" / " + s2);
// d1 = sdf.parse(s1);
// d2 = sdf.parse(s2);
// } catch (ParseException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// int i=0;
// if(d1.after(d2)){
// i=1;
// }
// //System.out.println(i);
// return i;
// }
// });
return map;
}
//获得起始日期
public static String [] getStartAndEnd(Date date, String type){
String [] sae = new String[2];
Calendar c = Calendar.getInstance();
SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
c.setTime(date);
String start = "";
String end = "";
if(type.equals("year")){ //按年
start = "01/01/"+c.get(Calendar.YEAR);
c.set(Calendar.MONTH, 11);
end = c.getActualMaximum(Calendar.DAY_OF_MONTH)+"/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.YEAR);
sae[0] = start;
sae[1] = end;
}else if(type.equals("month")){ //按月
start = "01/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.YEAR);
end = c.getActualMaximum(Calendar.DAY_OF_MONTH)+"/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.YEAR);
sae[0] = start;
sae[1] = end;
}else if(type.equals("day")){ //按日
start = c.get(Calendar.DATE)+"/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.YEAR);
end = c.get(Calendar.DATE)+"/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.YEAR);
sae[0] = start;
sae[1] = end;
}
return sae;
}
//获得起始日期
public static String [] getStartAndEnd(Date date){
String [] sae = new String[2];
Calendar c = Calendar.getInstance();
SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
c.setTime(date);
String start = "01/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.YEAR);
String end = c.getActualMaximum(Calendar.DAY_OF_MONTH)+"/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.YEAR);
sae[0] = start;
sae[1] = end;
return sae;
}
//获得中文或英文的月份号
public static String getMonth(Date date, int type){
String [] chiMonths = {"","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
String [] engMonths = {"","JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
String [] simMonths = {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
Calendar c = Calendar.getInstance();
String s = "";
if(type == 1)
s = chiMonths[c.get(Calendar.MONTH)+1];
else if(type == 2)
s = engMonths[c.get(Calendar.MONTH)+1];
else
s = simMonths[c.get(Calendar.MONTH)+1];
return s;
}
//获得中文或英文的星期号
public static String getWeek(Date date, int type){
Calendar c = Calendar.getInstance();
String [] chiWeeks = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
String [] engWeeks = {"","SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"};
String [] simWeeks = {"","Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
c.setTime(date);
String s = "";
if(type == 1)
s = chiWeeks[c.get(Calendar.DAY_OF_WEEK)];
else if(type ==2)
s = engWeeks[c.get(Calendar.DAY_OF_WEEK)];
else
s = simWeeks[c.get(Calendar.DAY_OF_WEEK)];
return s;
}
//得到当前日期的明天或昨天
public static long caculateResetTime(long currentTimestamp, int type){
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(currentTimestamp);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.roll(Calendar.DATE, type);
return cal.getTimeInMillis();
}
//得到当前日期的明天或昨天
public static long caculateResetTimestamp(long currentTimestamp, int type){
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(currentTimestamp);
cal.roll(Calendar.DATE, type);
return cal.getTimeInMillis();
}
//相差年数
public static int getYears(Date date_1, Date date_2){
int year = 0;
Calendar littleC = Calendar.getInstance(); //小的日期
littleC.setTime(date_1);
Calendar greatC = Calendar.getInstance(); //大的日期
greatC.setTime(date_2);
if(date_1.after(date_2)){
greatC.setTime(date_1);
littleC.setTime(date_2);
}else if(date_1.before(date_2)){
greatC.setTime(date_2);
littleC.setTime(date_1);
}
littleC.add(Calendar.YEAR, 1);
while(greatC.after(littleC)){
littleC.add(Calendar.YEAR, 1);
year++;
}
return year;
}
//相差月数
public static int getMonths(Date date1, Date date2){
int iMonth = 0;
int flag = 0;
try{
Calendar objCalendarDate1 = Calendar.getInstance();
objCalendarDate1.setTime(date1);
Calendar objCalendarDate2 = Calendar.getInstance();
objCalendarDate2.setTime(date2);
if (objCalendarDate2.equals(objCalendarDate1))
return 0;
if (objCalendarDate1.after(objCalendarDate2)){
Calendar temp = objCalendarDate1;
objCalendarDate1 = objCalendarDate2;
objCalendarDate2 = temp;
}
if (objCalendarDate2.get(Calendar.DAY_OF_MONTH) < objCalendarDate1.get(Calendar.DAY_OF_MONTH))
flag = 1;
if (objCalendarDate2.get(Calendar.YEAR) > objCalendarDate1.get(Calendar.YEAR))
iMonth = ((objCalendarDate2.get(Calendar.YEAR) - objCalendarDate1.get(Calendar.YEAR))
* 12 + objCalendarDate2.get(Calendar.MONTH) - flag)
- objCalendarDate1.get(Calendar.MONTH);
else
iMonth = objCalendarDate2.get(Calendar.MONTH)
- objCalendarDate1.get(Calendar.MONTH) - flag;
} catch (Exception e){
e.printStackTrace();
}
return iMonth;
}
//相差天数
public static int getDays2(Date g1, Date g2) {
int elapsed = 0;
Calendar gc1 = Calendar.getInstance();
Calendar gc2 = Calendar.getInstance();
Date d1, d2;
d1 = (Date) g1.clone();
d2 = (Date) g2.clone();
if (g2.after(g1)) {
gc2.setTime(d2);
gc1.setTime(d1);
} else {
gc2.setTime(d1);
gc1.setTime(d2);
}
gc1.clear(Calendar.MILLISECOND);
gc1.clear(Calendar.SECOND);
gc1.clear(Calendar.MINUTE);
gc1.clear(Calendar.HOUR_OF_DAY);
gc2.clear(Calendar.MILLISECOND);
gc2.clear(Calendar.SECOND);
gc2.clear(Calendar.MINUTE);
gc2.clear(Calendar.HOUR_OF_DAY);
while (gc1.before(gc2)) {
gc1.add(Calendar.DATE, 1);
elapsed++;
}
return elapsed;
}
//相差天数
public static int getDays(GregorianCalendar g1, GregorianCalendar g2) {
int elapsed = 0;
GregorianCalendar gc1, gc2;
if (g2.after(g1)) {
gc2 = (GregorianCalendar) g2.clone();
gc1 = (GregorianCalendar) g1.clone();
} else {
gc2 = (GregorianCalendar) g1.clone();
gc1 = (GregorianCalendar) g2.clone();
}
gc1.clear(Calendar.MILLISECOND);
gc1.clear(Calendar.SECOND);
gc1.clear(Calendar.MINUTE);
gc1.clear(Calendar.HOUR_OF_DAY);
gc2.clear(Calendar.MILLISECOND);
gc2.clear(Calendar.SECOND);
gc2.clear(Calendar.MINUTE);
gc2.clear(Calendar.HOUR_OF_DAY);
while (gc1.before(gc2)) {
gc1.add(Calendar.DATE, 1);
elapsed++;
}
return elapsed;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
// try {
// Date d = sdf.parse("2010/04/12");
// Date d2 = sdf.parse("2010/04/17");
// Calendar c = Calendar.getInstance();
// Calendar c2 = Calendar.getInstance();
// c.setTime(d);
// c2.setTime(d2);
// if(d.getTime()>d2.getTime()){
// System.out.println("大于");
// }else{
// System.out.println("小于");
// }
// System.out.println(d.getDate());
// } catch (ParseException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
String [] timeArrys = {"2010/2/22","2010/3/3","2010/4/21","2010/03/1","2010/1/28","2010/02/16","2010/4/09","2010/02/06"};
Date maxDate = null;
Date minDate = null;
SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd");
//日号与月号补零
for(int i=0; i<timeArrys.length; i++){
String [] a = timeArrys[i].split("/");
if(a[1].length()==1){
a[1]="0"+a[1];
}
if(a[2].length()==1){
a[2]="0"+a[2];
}
timeArrys[i]=a[0]+"/"+a[1]+"/"+a[2];
}
Date [] dates = new Date[timeArrys.length];
List dateList = Arrays.asList(timeArrys);
//利用List排序获得最大值和最小值
Collections.sort(dateList);
try{
maxDate = sf.parse(dateList.get(dateList.size()-1)+"");
minDate = sf.parse(dateList.get(0)+"");
}catch(ParseException e){
}
System.out.println("利用List排序获得最大值和最小值: ");
System.out.println(dateList);
System.out.println("最大值:"+ maxDate.toLocaleString());
System.out.println("最小值: "+ minDate.toLocaleString());
//使用TreeSe排序
for(int i=0; i<dateList.size(); i++){
try {
dates[i] = sf.parse(timeArrys[i]);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
SortedSet<Date> sset = new TreeSet<Date>(Arrays.asList(dates));
maxDate = sset.last();
minDate = sset.first();
System.out.println("使用TreeSe排序: ");
System.out.println("最大值:"+ maxDate.toLocaleString());
System.out.println("最小值: "+ minDate.toLocaleString());
//使用自定义排序方法
List<Date> dList = new ArrayList<Date>(Arrays.asList(dates));
Collections.sort(dList,new Comparator<Date>(){
@Override
public int compare(Date o1, Date o2) {
// TODO Auto-generated method stub
if(o1.after(o2)){
return 1;
}
return 0;
}
});
maxDate = dList.get(dList.size()-1);
minDate = dList.get(0);
System.out.println("使用自定义排序方法: ");
System.out.println("最大值:"+ maxDate.toLocaleString());
System.out.println("最小值: "+ minDate.toLocaleString());
int years = getYears(maxDate, minDate);
System.out.println("相差年数:" + years);
int result = 0;
Date d = null;
Date d2 = null;
try {
d = sdf.parse("2010/02/16");
d2 = sdf.parse("2010/02/17");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
GregorianCalendar gc1 = new GregorianCalendar();
GregorianCalendar gc2 = new GregorianCalendar();
gc1.setTime(d);
gc2.setTime(d2);
result = getDays2(maxDate, minDate);
System.out.println("相差天数: "+result);
result = getMonths(d,d2);
System.out.println("相差月数: "+result);
Calendar cc = Calendar.getInstance();
cc.setTime(d);
//得到该月最大的天数
System.out.println(cc.get(Calendar.YEAR)+"/"+(cc.get(Calendar.MONTH)+1)+"/"+cc.get(Calendar.DATE)+"该月有: "+cc.getActualMaximum(Calendar.DAY_OF_MONTH)+" 天");
// long timestamp = caculateResetTimestamp(new Date().getTime(),1);
// long timestamp2 = caculateResetTimestamp(new Date().getTime(), -1);
// Date tomorrow = new Date(timestamp);
// Date yesterday = new Date(timestamp2);
// System.out.println("明天日期:" + tomorrow.toLocaleString());
// System.out.println("昨天日期:" + yesterday.toLocaleString());
//
// long timeTomorrom = caculateResetTime(new Date().getTime(),1);
// long timeYesterday = caculateResetTime(new Date().getTime(), -1);
// Date tomorrowReset = new Date(timeTomorrom);
// Date yesterdayReset = new Date(timeYesterday);
// System.out.println("明天起始日期:" + tomorrowReset.toLocaleString());
// System.out.println("昨天起始日期:" + yesterdayReset.toLocaleString());
//
// String week = getWeek(new Date(), 1);
// System.out.println("当前日期的中文星期号是:" + week );
// week = getWeek(new Date(),0);
// System.out.println("当前日期的英文星期号是:" + week );
//
// String month = getMonth(new Date(), 1);
// System.out.println("当前日期的中文月份号是:" + month );
// month = getMonth(new Date(),0);
// System.out.println("当前日期的英文月份号是:" + month );
// String [] sae = getStartAndEnd(new Date());
// System.out.println("当前时间的第一天和最后一天:"+ sae[0]+" : " + sae[1]);
try {
d = sdf.parse("2005/02/16");
d2 = sdf.parse("2010/02/17");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("按年分割时间段:" + getTimeWeaveByYear(d,d2));
System.out.println("格式化日期: " + formatDate(getTimeWeaveByYear(d,d2)));
Map<String, String[]> map = getStartEndGroup(formatDate(getTimeWeaveByYear(d,d2)));
// Set set = map.entrySet();
// java.util.Map.Entry entries[] = (java.util.Map.Entry[])set.toArray(new java.util.Map.Entry[set.size()]);
// Arrays.sort(entries, new Comparator() {
// public int compare(Object arg0, Object arg1){
// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
// Date d1 = null;
// Date d2 = null;
// try {
//
// String s1 = ((Map.Entry)arg0).getKey().toString();
// String s2 = ((Map.Entry)arg1).getKey().toString();
// System.out.println(s1+" / " + s2);
// d1 = sdf.parse(s1);
// d2 = sdf.parse(s2);
// } catch (ParseException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// int i=0;
// if(d1.after(d2)){
// i=1;
// }
// System.out.println(i);
// return i;
// }
// });
Set<String> st = map.keySet();
for(Iterator<String> it = st.iterator(); it.hasNext(); ){
String key = it.next();
String [] ss = map.get(key);
System.out.println("2222222key: " + key + " value: " + ss[0]+" : " + ss[1]);
}
try {
d = sdf.parse("2010/02/16");
d2 = sdf.parse("2010/09/17");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("按月分割时间段:" + getTimeWeaveByMonth(d,d2));
System.out.println("格式化日期: " + formatDate(getTimeWeaveByMonth(d,d2)));
Map<String, String[]> map2 = getStartEndGroup(formatDate(getTimeWeaveByMonth(d,d2)));
Set<String> set2 = map2.keySet();
for(Iterator<String> it = set2.iterator(); it.hasNext(); ){
String key = it.next();
String [] ss = map2.get(key);
System.out.println("key: " + key + " value: " + ss[0]+" : " + ss[1]);
}
try {
d = sdf.parse("2010/02/16");
d2 = sdf.parse("2010/02/28");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("按天分割时间段:" + getTimeWeaveByDay(d,d2));
System.out.println("格式化日期: " + formatDate(getTimeWeaveByDay(d,d2)));
Map<String, String[]> map3 = getStartEndGroup(formatDate(getTimeWeaveByDay(d,d2)));
Set<String> set3 = map3.keySet();
for(Iterator<String> it = set3.iterator(); it.hasNext(); ){
String key = it.next();
String [] ss = map3.get(key);
System.out.println("key: " + key + " value: " + ss[0]+" : " + ss[1]);
}
Calendar cccc = Calendar.getInstance();
cccc.setTime(new Date());
cccc.set(Calendar.MONTH, 3);
System.out.println(cccc.getActualMaximum(Calendar.DAY_OF_MONTH));
String [] sss = getStartAndEnd(new Date(), "day");
for(String s : sss){
System.out.println(s);
}
}
}
发表评论
-
日期比较
2013-06-13 16:21 1176比较日期: function compareDate( ... -
Arrays.asList详解
2012-09-10 09:52 889Arrays.asList详解 记得以前写过一 ... -
Collections.addAll
2012-09-07 18:04 2330collections用法以及list 简单实例 Colle ... -
string
2012-09-06 17:20 892String a = "ab"; ... -
图片复制
2012-07-05 11:53 1068import java.io.File;import java ... -
thumbnailator 图片缩放
2012-07-04 20:10 1386Thumbnailator是一个用来生成图像缩略图的 J ... -
java File
2012-06-29 13:53 1278直接下载的,整理的很好,这里做个记录,基础的东西都是。 Fi ... -
mysql 时间比较
2012-06-05 19:57 1弱智得问题,分开写 SELECT * FROM bb_ ... -
split
2012-05-23 10:46 1203//String[] idArr = StringUtil ... -
(转)关于Integer大小比较的问题
2012-05-18 10:32 879关于Integer大小比较的问题 昨天跟朋友一起 ... -
toString
2012-05-14 20:01 1005public abstract class ToStringB ... -
io读取操作
2012-03-09 16:18 963public void writeFile(Strin ... -
string[] to map
2012-03-03 17:23 1086public static Map<Inte ... -
tomcat中文问题的解决
2012-03-01 09:55 862第一,存文件必须以一种编码存;读文件也必须以一种编码读,如不特 ... -
java方式将汉字转成拼音
2012-02-24 13:02 1063/** * 需要一个开源的jar包pinyin4j-2.5. ... -
System.getProperty(key)
2012-02-15 15:08 1021public static void main(String ... -
CodeFilter
2012-05-22 11:14 840package com.bitbao.cm.common.ut ... -
Integer值比较误区
2012-05-22 11:14 938例子: Integer i1 = 12; I ... -
容易忽略的for循环问题
2012-01-18 15:33 11761、项目中对用户操作的结果进行审核时候,出现一个问题,如果对省 ... -
java实现的加密工具类(支持MD5和SHA)
2012-01-13 16:08 1273版权声明: dtstudy原创文章,转载请注明出处: h ...
相关推荐
JavaCalendar是Java编程语言中用于处理日期和时间的重要类,它是`java.util.Calendar`的实现。这个源码分析将深入探讨Java中日期和时间的管理,以及如何利用`Calendar`类进行相关的操作。 首先,`Calendar`类是抽象...
在Java编程语言中,`Calendar`和`Date`类是处理日期和时间的核心组件。这两个类在处理日期、时间计算以及格式化等任务时扮演着关键角色。理解并熟练运用它们,对于提升Java开发能力至关重要。 `Date`类是Java早期...
在Java编程语言中,`Date`和`Calendar`类是处理日期和时间的核心组件。这两个类在不同的Java版本中有着不同的使用方式和功能,对于理解Java时间处理机制至关重要。本篇将深入探讨`Date`和`Calendar`类的实例应用。 ...
JavaCalendar是一个在Java环境中用于处理和显示时间的组件,尤其在Java Swing应用中,由于J Swing自身并未内置专门的时间控件,JavaCalendar就显得尤为重要。它提供了用户友好的界面,帮助开发者实现对日期和时间的...
### Java中的Calendar类详解 #### 一、引言 在Java中处理日期和时间非常常见,而`java.util.Calendar`类则是进行此类操作的核心工具之一。`Calendar`类提供了一系列的功能来帮助开发者处理复杂的日期计算问题,...
Java Calendar类使用总结及使用实例 Java Calendar类是Java语言中用于处理日期和时间的类,它提供了许多方法来获取和设置日期和时间。下面是Java Calendar类的使用总结及使用实例: 1. 获取Calendar实例 Java ...
在Java编程语言中,`Calendar`类是一个核心的日期和时间API,它用于处理各种日历系统,而不仅仅是常见的格里高利历(Gregorian Calendar)。`Calendar`是一个抽象类,这意味着它不能直接被实例化,但是提供了`...
Java Calendar手机上期选择-日历实现 // 重载抽象类MIDlet的抽象方法startApp() protected void startApp() { Date dd = new Date(); // 表示当前的日期和时间 TimeZone tz = TimeZone.getTimeZone("GMT...
Java中的Date和Calendar类是处理日期和时间的核心组件。Date类主要用于表示特定的瞬间,精确到毫秒。在早期版本的Java中,Date类的设计受到批评,因为它的API不直观且容易导致错误。为了解决这些问题,大部分日期和...
Java Calendar日历与Date日期的相互转换详解 Java Calendar日历与Date日期的相互转换是Java开发中的一项基本技术,掌握这项技术可以帮助开发者更好地处理日期和时间相关的操作。在本文中,我们将详细介绍Java ...
Java Calendar 类是 Java 语言中用于处理日期和时间的核心类之一。它是一个抽象类,提供了丰富的功能来操作日期,如获取、设置年份、月份、日期、小时等信息,以及进行日期之间的比较和计算。在Java 8之后,虽然引入...
在Java中,通过`Calendar`类可以方便地操作日期。以下将详细介绍如何利用`Calendar`类来获取本周、本年、本月的第一天和最后一天的具体实现方法。 #### 本周的第一天与最后一天 在Java中,获取本周的第一天和最后...
4. **日期模型**:JCalendar使用Java的`java.util.Calendar`类作为其日期模型,这意味着它可以直接与Java标准日期处理库进行无缝集成,方便数据的读取和存储。 5. **组件组合**:JCalendar不仅可以作为一个独立的...
压缩包文件名“javaCalendar”可能包含了示例代码或者扩展了`Calendar`功能的库,这将有助于进一步学习和理解如何在实际项目中有效利用`Calendar`控件。如果包含的是代码示例,通过分析和运行这些示例,开发者可以更...
在Java编程语言中,`Calendar`类是处理日期和时间的核心工具之一,它提供了一种可以操作日期和时间字段(如年、月、日、时、分、秒等)的灵活方式。`Calendar`类是抽象的,因此我们通常通过其子类如`...
Java中的`Calendar`类是处理日期和时间的核心类,它是一个抽象类,提供了一系列方法用于在特定瞬间与一组日历字段之间进行转换和操作。自JDK 1.1起,`Calendar`类就被推荐用来处理日期和时间,因为它的功能比`Date`...
从JDK1.1版本开始,在处理日期和时间时,系统推荐使用Calendar类进行实现。在设计上,Calendar类的功能要比Date类强大很多,而且在实现方式上也比Date类要复杂一些,下面就介绍一下Calendar类的使用。
Java Calendar日历类原理及使用方法 Java Calendar日历类是Java语言中的一种日历类,用于处理日期和时间相关的操作。该类提供了许多有用的方法来获取和设置日期和时间的信息。 日历类原理 Java Calendar日历类是...
Java中的时间类`Date`和`Calendar`是处理日期和时间的核心组件,它们在Java编程中扮演着重要的角色。在Java中,`Date`类主要用来表示特定的瞬间,精确到毫秒。而`Calendar`类则是一个抽象类,提供了比`Date`更灵活的...
在Java编程语言中,`Calendar`类是用于处理日期和时间的核心类之一。这个`基于Java的Calendar万年历.zip`文件很可能包含了一个示例项目,演示如何利用`Calendar`类构建一个显示从公元前到公元后数千年日期的万年历。...