如何用java计算时间到微秒
6个回答
展开全部
使用Date类的getTime()方法
下面是示例代码,比如你要统计代码的执行时间:
import java.util.Date;
public class Test {
public static void main(String[] args) {
long begin = new Date().getTime();
double d = 4;
for (int i = 0; i < 200000; i++){
d += 4;
}
System.out.println(d);
long end = new Date().getTime();
System.out.println(end - begin);
}
}
下面再看一下getTime的定义:
/**
* Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this <tt>Date</tt> object.
*
* @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this date.
*/
public long getTime() {
return getTimeImpl();
}
milliseconds就是微妙的意思,所以getTime的精度是微妙
展开全部
long begintime = System.currentTimeMillis();
...
long endtime = System.currentTimeMillis();
开始和结束都使用这个来取得时间,差值就是时间段的微妙数
...
long endtime = System.currentTimeMillis();
开始和结束都使用这个来取得时间,差值就是时间段的微妙数
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
引用uqortbsa的回答:
使用Date类的getTime()方法
下面是示例代码,比如你要统计代码的执行时间:
import java.util.Date;public class Test { public static void main(String[] args) { long begin = new Date().getTime(); double d = 4; for (int i = 0; i < 200000; i++){ d += 4; } System.out.println(d); long end = new Date().getTime(); System.out.println(end - begin); }}下面再看一下getTime的定义:
/** * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this <tt>Date</tt> object. * * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this date. */ public long getTime() { return getTimeImpl(); }milliseconds就是微妙的意思,所以getTime的精度是微妙
使用Date类的getTime()方法
下面是示例代码,比如你要统计代码的执行时间:
import java.util.Date;public class Test { public static void main(String[] args) { long begin = new Date().getTime(); double d = 4; for (int i = 0; i < 200000; i++){ d += 4; } System.out.println(d); long end = new Date().getTime(); System.out.println(end - begin); }}下面再看一下getTime的定义:
/** * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this <tt>Date</tt> object. * * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this date. */ public long getTime() { return getTimeImpl(); }milliseconds就是微妙的意思,所以getTime的精度是微妙
展开全部
milliseconds 的意思是 毫秒,别人问的是微秒,请不要误导大家
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
引用uqortbsa的回答:
使用Date类的getTime()方法
下面是示例代码,比如你要统计代码的执行时间:
import java.util.Date;public class Test { public static void main(String[] args) { long begin = new Date().getTime(); double d = 4; for (int i = 0; i < 200000; i++){ d += 4; } System.out.println(d); long end = new Date().getTime(); System.out.println(end - begin); }}下面再看一下getTime的定义:
/** * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this <tt>Date</tt> object. * * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this date. */ public long getTime() { return getTimeImpl(); }milliseconds就是微妙的意思,所以getTime的精度是微妙
使用Date类的getTime()方法
下面是示例代码,比如你要统计代码的执行时间:
import java.util.Date;public class Test { public static void main(String[] args) { long begin = new Date().getTime(); double d = 4; for (int i = 0; i < 200000; i++){ d += 4; } System.out.println(d); long end = new Date().getTime(); System.out.println(end - begin); }}下面再看一下getTime的定义:
/** * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this <tt>Date</tt> object. * * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this date. */ public long getTime() { return getTimeImpl(); }milliseconds就是微妙的意思,所以getTime的精度是微妙
展开全部
milliseconds,ms,这叫毫秒,Ctrl c+v 也要睁着眼行吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询