【例子】获取系统时间

// 获取long型系统时间,精确到秒
Calendar ca = Calendar.getInstance();
long systemTime = (long) (ca.getTimeInMillis() / 1000);

//或者
long systemTime = System.currentTimeMillis() / 1000;

--------------------------------------------------------------------------------

    /**
     * 超时处理的时间要求可配,因此写到配置文件中。
     */
    private static final String timeOutConf = "classes/voipDetailBillTimeOut.properties";

    // 取得 long型 指定日期的指定时间
    Calendar ca = Calendar.getInstance();
    ca.setTimeInMillis( long型时间 );
    ca.set(Calendar.HOUR_OF_DAY, 23);
    ca.set(Calendar.MINUTE, 59);
    ca.set(Calendar.SECOND, 59);
    long endTime = ca.getTimeInMillis() / 1000;

--------------------------------------------------------------------------------

       /**
        * 获取系统时间
        */ 
       public String getDate(){ 
            
            Calendar ca = Calendar.getInstance(); 
             int year = ca.get(Calendar.YEAR);//获取年份 
             int month=ca.get(Calendar.MONTH);//获取月份  
             int day=ca.get(Calendar.DATE);//获取日 
             int minute=ca.get(Calendar.MINUTE);//分  
             int hour=ca.get(Calendar.HOUR);//小时  
             int second=ca.get(Calendar.SECOND);//秒 
              
             String date = year + "年" + (month + 1 )+ "月" + day + "日"+ hour + "时" + minute + "分" + second + "秒";    
             return date;             
       }

你可能感兴趣的:(系统时间)