📄 count.java
字号:
/*
* Created on 2004-12-6
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.bwm.time;
import java.util.StringTokenizer;
/***************************************************
*class explain: Count time<br>
*set up name: crazyadept<br>
*set up time: 12/06/004
****************************************************/
public class Count {
private Time nowtime;
private StringTokenizer st=null;
private String array[]=null;
private String narray[]=null;
private int num=0;
private int nnum=0;
private String nstr;
/***************************************************
*return value: value<0 : less than now time<br>
* value=0 : equas now time<br>
* value>0 : more than now time<br>
*parameter: year:month:date<br>
*set up name: crazyadept<br>
*set up time: 12/10/2004<br>
*change time: 12/07/2004
****************************************************/
public int compareTime(String str){
try{
st=new StringTokenizer(str,"-");
num=st.countTokens();
array=new String[num];
//decompose str
str="";
for(int i=0;st.hasMoreElements();i++){
array[i]=st.nextToken();
if(array[i].length()==1){
array[i]="0"+array[i];
}
str=str+array[i]+"-";
}
nowtime=new Time();
nstr=nowtime.getYMD();
st=new StringTokenizer(nstr,"-");
nnum=st.countTokens();
narray=new String[nnum];
nstr="";
for(int i=0;st.hasMoreElements();i++){
narray[i]=st.nextToken();
if(narray[i].length()==1){
narray[i]="0"+narray[i];
}
nstr=nstr+narray[i]+"-";
}
}catch(Exception e){
System.err.print(e.getMessage());
e.printStackTrace();
}
return str.compareTo(nstr);
}
/***************************************************
*return value: year:month:date<br>
*parameter: year:month:date and prolong month<br>
*set up name: crazyadept<br>
*set up time: 12/07/2004<br>
*change time: 12/07/2004
****************************************************/
public String addMonth(String str,int j){
if(j<=0){
return str;
}
st=new StringTokenizer(str,"-");
num=st.countTokens();
array=new String[num];
try{
//decompose str
for(int i=0;st.hasMoreElements();i++){
array[i]=st.nextToken();
}
int year=Integer.parseInt(array[0]);
int month=Integer.parseInt(array[1])+j;
//add year and month
if(month>=12){
int mod=month%12;
if(mod==0){
year=year+month/12;
month=12;
}else{
year=year+month/12;
month=mod;
}
}
array[0]=(new Integer(year)).toString();
array[1]=(new Integer(month)).toString();
if(array[1].length()==1){
array[1]="0"+array[1];
}
if(array[2].length()==1){
array[2]="0"+array[2];
}
//compose str
str="";
for(int i=0;i<num;i++){
str=str+array[i]+"-";
}
str=str.substring(0,str.length()-1);
}catch(Exception e){
System.err.print(e.getMessage());
e.printStackTrace();
}
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -