Java获取精确到毫秒的时间戳

 

 

import java.util.Date;

public class Timestamp {

    /** 
      获取精确到毫秒的时间戳 
     * @param date 
     * @return 
     **/  
    public static Long getTimestamp(Date date){  
        if (null == date) {  
            return (long) 0;  
        }  
        String timestamp = String.valueOf(date.getTime());  
        return Long.valueOf(timestamp);  
    }  
    
    public static void main(String[] args) {
        Date d = new Date();
        System.out.println(getTimestamp(d));
     //结果:1504535566231
    }
}

 

posted @ 2017-09-04 22:40  就这个名字好  阅读(25721)  评论(0编辑  收藏  举报