如题 有需求如下 上传文件 文件名以当前精确到毫秒的系统时间为定  例子 20100718233524786.jpg就是在2010年07月18号23点35分24.786秒上传的文件   求高手指教 

解决方案 »

  1.   

    System.currentTimeMillis()更精确的
    System.nanoTime()
      

  2.   

    public static void main(String[] args) {
    Calendar now=Calendar.getInstance(); 
    int month = now.get(Calendar.MONTH) + 1;
    String m = "";

    if(month < 10) {
    m = "0"+month;
    }

    String time = now.get(Calendar.YEAR)+ m + now.get(Calendar.DAY_OF_MONTH) + 
                  now.get(Calendar.HOUR_OF_DAY)+now.get(Calendar.MINUTE)+
                  now.get(Calendar.SECOND)+now.get(Calendar.MILLISECOND);
    System.out.println(time); }
      

  3.   

    import java.util.Calendar;/**
     * 获取当年时间的字符串
     * @author Wang
     *
     */
    public class GetTime { public static void main(String[] args) {
    Calendar now=Calendar.getInstance(); 
    int month = now.get(Calendar.MONTH) + 1;
    String m = "";

    if(month < 10) {
    m = "0"+month;
    }

    String time = now.get(Calendar.YEAR)+ m + now.get(Calendar.DAY_OF_MONTH) + 
                  now.get(Calendar.HOUR_OF_DAY)+now.get(Calendar.MINUTE)+
                  now.get(Calendar.SECOND)+now.get(Calendar.MILLISECOND);
    System.out.println(time);
    System.out.println(System.currentTimeMillis());
    System.out.println(System.nanoTime());
    }}
      

  4.   

    new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
      

  5.   

    这样也不能保证唯一性。如果有并发过来的话,还是会产生重复。建议使用 UUID(UUID.randomUUID().toString() 方法产生)作为文件名,这样可以保证唯一性,比如 CSDN 帖子的文件名称。
      

  6.   

    这返回的是一个距离标准时间的毫秒数吧 如果想要转换当前系统时间 还需要一个很麻烦的算法 有没有更简单的方法或者是java提供的方法来完成的