怎么把系统当前时间转化为形如“874965758”Unix秒的形式
UTC时间1970年1月1日0时0分0秒就是UNIX时间0, UTC时间1970年1月2日0时0分0秒就是UNIX时间86400.
望高手帮忙!

解决方案 »

  1.   

    System.out.println(System.currentTimeMillis());
    剩下的自己搞定吧 无非就是个加减法了
      

  2.   

    To convert from local timezone to UTCpublic static String convertLocalTimeToUTC(String p_city, String p_localDateTime) throws Exception{  
     
    String lv_dateFormateInUTC="";//Will hold the final converted date  
    Datelv_localDate = null;  
    Stringlv_localTimeZone ="";  
    SimpleDateFormat lv_formatter;  
    SimpleDateFormat lv_parser;  
        
    //Temp for testing(mapping of cities and timezones will eventually be in a properties file  if(p_city.equals("LON")){  
    lv_localTimeZone="Europe/London";  
    }else if(p_city.equals("NBI")){  
    lv_localTimeZone="EAT";  
    }else if(p_city.equals("BRS")){  
    lv_localTimeZone="Europe/Brussels";  
    }else if(p_city.equals("MNT")){  
    lv_localTimeZone="America/Montreal";  
    }else if(p_city.equals("LAS")){  
    lv_localTimeZone="PST";  
    }  
      
    //create a new Date object using the timezone of the specified city  
    lv_parser = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");  
    lv_parser.setTimeZone(TimeZone.getTimeZone(lv_localTimeZone));  lv_localDate = lv_parser.parse(p_localDateTime);  
      
    //Set output format prints "2007/10/25  18:35:07 EDT(-0400)"  
    lv_formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z'('Z')'");  
    lv_formatter.setTimeZone(TimeZone.getTimeZone(lv_localTimeZone));  
      
    System.out.println("convertLocalTimeToUTC: "+p_city+": "+" The Date in the local time zone " + lv_formatter.format(lv_localDate));  
      
    //Convert the date from the local timezone to UTC timezone  
    lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));  
    lv_dateFormateInUTC = lv_formatter.format(lv_localDate);  
    System.out.println("convertLocalTimeToUTC: "+p_city+": "+" The Date in the UTC time zone " + lv_dateFormateInUTC);  
       return lv_dateFormateInUTC;  
    }  
      

  3.   

    System.out.println(new java.sql.Timestamp(System.currentTimeMillis());
      

  4.   

    我想的太麻烦了,System.currentTimeMillis()/1000应该就可以了