java毫秒_JAVA中怎么获取毫秒和微秒数
1.
long java.util.Date.getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
如上JDK文檔說,在Date對象上用getTime()獲得自1970年1月1日以來的毫秒數。
2.
System.currentTimeMillis(); 這個方法獲取當前時間的毫秒數。
3.
以下實例代碼把通過毫秒數相減算的目前距2014-10-01 00:00:00的天數。
public class Test {public static void main(String[] args) throws ParseException {SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String start="2014-10-01 00:00:00";//得到毫秒數long timeStart=sdf.parse(start).getTime();long justNow =System.currentTimeMillis();//兩個日期想減得到天數long dayCount= (justNow-timeStart)/(24*3600*1000);System.out.println(dayCount);}}輸出
25
取消
評論
總結
以上是生活随笔為你收集整理的java毫秒_JAVA中怎么获取毫秒和微秒数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 怎么存储毫秒,MySQL存储
- 下一篇: MySQL 查询各年龄段