CSDN博客

img flyying

rowAutoID

发表于2004/10/18 11:04:00  361人阅读

/*
 * Copyright (c) 2003 沈阳华新网络物业公司.  All rights
 * reserved.
 * 公用Bean,产生数据库记录的主键ID
 * 形式:年月日时分秒百万分之一秒+6位随机数
 */

package zpxx;

import java.text.DateFormat;
import java.util.*;

public class rowAutoID {
    Calendar  calendar = null;
    Date currentDate;

    public rowAutoID() {
 calendar = Calendar.getInstance();
 Date trialTime = new Date();
 calendar.setTime(trialTime);
    }


    public int getYear() {
 return calendar.get(Calendar.YEAR);
    }
   
    public String getMonth() {
 int m = getMonthInt();
 String[] months = new String [] { "01", "02", "03", "04", "05", "06", "07", "08", "09",
     "10", "11", "12" };
 
 return months[m - 1];

    }

    public int getMonthInt() {
 return 1 + calendar.get(Calendar.MONTH);
    }

    public String getDate() {
 return getYear() + "" + getMonth() + "" + getDayOfMonth() ; 
    }

    public String getCurrentDate() {
        Date dt = new Date ();
 calendar.setTime (dt);
        return getYear() + "-" + getMonth() + "-" + getDayOfMonth();
      }

   public String getCurrentDate(String arg1) {
        Date dt = new Date ();
 calendar.setTime (dt);
        if(arg1.equals("1"))
   return getYear() + "-" + getMonth() + "-" + getDayOfMonth();
        else
          return getYear() + "-" + getMonth() + "-" + getDayOfMonth() + " " + getTCurrentime();
    }

    public String getTime() {
 return getHour() + "" + getMinute() + "" + getSecond() + "" + getMilliSecond();
    }

    public String getTCurrentime() {
 return getHour() + ":" + getMinute() + ":" + getSecond();
    }

    public String getDayOfMonth() {
 int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
 String StrTmp;
 if(dayOfMonth < 10) StrTmp="0" + dayOfMonth;
  else StrTmp = "" + dayOfMonth;
 return StrTmp;
    }

    public String getHour() {
 int hour = calendar.get(Calendar.HOUR_OF_DAY);
 String StrTmp;
 if(hour < 10) StrTmp="0" + hour;
  else StrTmp = "" + hour;
 return StrTmp;
    }
   
    public String getMinute() {
 int minute = calendar.get(Calendar.MINUTE);
 String StrTmp;
 if(minute < 10) StrTmp="0" + minute;
  else StrTmp = "" + minute;
 return StrTmp;
    }

    public String getSecond() {
 int second = calendar.get(Calendar.SECOND);
 String StrTmp;
 if(second < 10 ) StrTmp = "0" + second;
  else StrTmp = "" + second;
 return StrTmp;
    }

    public int getMilliSecond() {
 return calendar.get(Calendar.MILLISECOND);
    }

    public int getRandomNum() {
 int MaxInt=1000000;
 Random r = new Random();
 int getRandomNum=r.nextInt(MaxInt);
 return getRandomNum;
    }

    public String getRowAutoID() {
 return getDate() + getTime() + getRandomNum();
    }

}

阅读全文
0 0

相关文章推荐

img
取 消
img