long i=(now()).getTime();
long j=(BIRTH_DATE).getTime();
long x=i-j;
Date t=new Date();
t.setTime(x);
String str=t.toString();

解决方案 »

  1.   

    sql server里
    select cast((cast(now as int) - cast(birthdate as int))/365 as char(3)  AS age from table   ------------------------------------------------------
               我们还年轻牛奶会有的奶牛也会有的 
                 可天天在 csdn 混这些会有吗 ??
      

  2.   

    char(3) 后面少写了个 ) ------------------------------------------------------
               我们还年轻牛奶会有的奶牛也会有的 
                 可天天在 csdn 混这些会有吗 ??
      

  3.   

    //你是不是想要这个
    /**
     * 通过生日得到年龄
     * @param java.util.Date
     * @return int
     */
    public static int getAgeByBirthday(java.util.Date birthday) {
    int age = 0;
    GregorianCalendar calendar = new GregorianCalendar();
    int curYear = calendar.get(Calendar.YEAR);
    int curMonth = calendar.get(Calendar.MONTH) + 1;
    int curDate = calendar.get(Calendar.DATE);
    if (birthday != null) {
    calendar.setTime(birthday);
    int birthYear = calendar.get(Calendar.YEAR);
    int birthMonth = calendar.get(Calendar.MONTH) + 1;
    int birthDate = calendar.get(Calendar.DATE);
    if (curMonth < birthMonth) {
    age = curYear - birthYear - 1;
    } else if (curMonth == birthMonth) {
    if (curDate < birthDate)
    age = curYear - birthYear - 1;
    }
    age = curYear - birthYear;
    }
    return age;
    }
      

  4.   

    写错了一句
    /**
     * 通过生日得到年龄
     * @param java.util.Date
     * @return int
     */
    public static int getAgeByBirthday(java.util.Date birthday) {
    int age = 0;
    GregorianCalendar calendar = new GregorianCalendar();
    int curYear = calendar.get(Calendar.YEAR);
    int curMonth = calendar.get(Calendar.MONTH) + 1;
    int curDate = calendar.get(Calendar.DATE); if (birthday != null) {
    calendar.setTime(birthday);
    int birthYear = calendar.get(Calendar.YEAR);
    int birthMonth = calendar.get(Calendar.MONTH) + 1;
    int birthDate = calendar.get(Calendar.DATE); if (curMonth < birthMonth) {
    age = curYear - birthYear - 1;
    } else if (curMonth == birthMonth) {
    if (curDate < birthDate)
    age = curYear - birthYear - 1;
    }else{
    age = curYear - birthYear;
    }
    } return age;
    }
      

  5.   

    sql server里
    select cast((cast(now as int) - cast(birthdate as int))/365 as char(3)  AS age from table   ------------------------------------------------------
       cast将日期转换成数字型后所得到的数据并不是天数,你必须先取得这个日期的天数后才能这样转换