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 } }
时间: 2024-10-20 23:59:06