用下面的:
    private String getCurrentTime() {
        String strReturn="";
        NSTimestamp currentTime = new NSTimestamp();
        strReturn = currentTime.toString();
        return strReturn;
    }

解决方案 »

  1.   

    public class CurrentTime {
      public  static String getYearToMinuteCurrentTime(){  //取得本地的系统时间格式: yymmddhhmm 共十位
        StringBuffer send=new StringBuffer(10);
        Calendar sendTime=Calendar.getInstance();
        int minute=sendTime.get(Calendar.MINUTE);
        int hour=sendTime.get(Calendar.HOUR_OF_DAY);
        int day =sendTime.get(Calendar.DAY_OF_MONTH);
        int month=sendTime.get(Calendar.MONTH)+1;
        int year =sendTime.get(Calendar.YEAR);
        if(year>=2000) year=year-2000;
        else year=year-1900;
        send.append(getFormatTime(year,2));
        send.append(getFormatTime(month,2));
        send.append(getFormatTime(day,2));
        send.append(getFormatTime(hour,2));
        send.append(getFormatTime(minute,2));
        return send.toString();
      }
      public  static String getYearToSecondCurrentTime(){  //取得本地的系统时间格式: yymmddhhmmss 共12位
        StringBuffer send=new StringBuffer(10);
        Calendar sendTime=Calendar.getInstance();
        int second=sendTime.get(Calendar.SECOND);
        int minute=sendTime.get(Calendar.MINUTE);
        int hour=sendTime.get(Calendar.HOUR_OF_DAY);
        int day =sendTime.get(Calendar.DAY_OF_MONTH);
        int month=sendTime.get(Calendar.MONTH)+1;
        int year =sendTime.get(Calendar.YEAR);
        if(year>=2000) year=year-2000;
        else year=year-1900;
        send.append(getFormatTime(year,2));
        send.append(getFormatTime(month,2));
        send.append(getFormatTime(day,2));
        send.append(getFormatTime(hour,2));
        send.append(getFormatTime(minute,2));
        send.append(getFormatTime(second,2));
        return send.toString();
      }  private static String getFormatTime(int time,int format){  //取得任意位的字符串
        StringBuffer numm=new StringBuffer();
        int length=String.valueOf(time).length();    if(format<length) return null;    for(int i=0 ;i<format-length ;i++){
            numm.append("0");
        }
        numm.append(time);
        return numm.toString().trim();
      }  public static String getYearToMilMinuteCurrentTime(){ //取得本地的系统时间格式: yymmddhhmmssmis 共十五位
        StringBuffer send=new StringBuffer(15);
        Calendar sendTime=Calendar.getInstance();
        int second = sendTime.get(Calendar.SECOND);
        int miltime=sendTime.get(Calendar.MILLISECOND);
        send.append(getYearToMinuteCurrentTime());
        send.append(getFormatTime(second,2));
        send.append(getFormatTime(miltime,3));
        return send.toString();
      }}你可以参考上面的代码,写自己所需的函数
      

  2.   

    java.lang
    Code Samples Index 
    These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms 
    Getting the Current Time
    There are two ways of getting the current time.  // One way
     long time = System.currentTimeMillis();
         
     // Another way
     Date now = new Date(); 
      

  3.   

    I got a solution, share with you all:
        Calendar rightNow = Calendar.getInstance();
        int year,month,day,hour,minute,second;
        year = rightNow.get(YEAR);
        month = rightNow.get(MONTH);
        day = rightNow.get(DAY_OF_MONTH);
        hour = rightNow.get(HOUR_OF_DAY);
        minute = rightNow.get(MINUTE);
        second = rightNow.get(SECOND);
       
        String strDate = ""+year+"-"+month+"-"+day;
        String strTime = ""+hour+":"+minute+":"+second;  
        sexHome.create(hsid,sxid,sxname,oper,strDate,strTime);
      

  4.   

    /**
    *得到格式化后的系统当前日期
    *@param strScheme 格式模式字符串
    *@return 格式化后的系统当前时间,如果有异常产生,返回空串""
    *@see java.util.SimpleDateFormat
    */
    public static final String getNowDateTime(String strScheme)
    {
        String strReturn=null;
        Date now = new Date();     try
        {
                SimpleDateFormat sdf = new SimpleDateFormat(strScheme);
                strReturn=sdf.format(now);
            }
            catch(Exception e)
            {
                strReturn="";
            }
            return strReturn;
        }
      

  5.   

    试一试下面的程序,应该没有问题
    import java.util.*;
    class a
    { public static void main(String args[])
      {
        Date d = new Date();
        System.out.println(d.getTime());
        System.out.println(d.getTime()/1000/3600/24/365);
        System.out.println("----------------------------");
        Calendar  c = Calendar.getInstance();
        System.out.print(c.get(Calendar.YEAR)+" 年 " +
                         (c.get(Calendar.MONTH)+1)+" 月 " +
                         c.get(Calendar.DATE)+" 日   " );
        System.out.println(c.get(Calendar.HOUR)+ " 时 " +
                           c.get(Calendar.MINUTE)+ " 分 " +
                           c.get(Calendar.SECOND)+ " 秒 ");
        System.out.println(c.getTime().getTime());
        c.set(2001,4,1);           //  2001/5/1
        System.out.println(c.get(Calendar.YEAR)+" 年 " +
                         (c.get(Calendar.MONTH)+1)+" 月 " +
                         c.get(Calendar.DATE)+" 日   " );
        System.out.println(c.getTime().getTime()/1000/3600/24/365);
      }
    }