易截截图软件、单文件、免安装、纯绿色、仅160KB

Java中的时间精度

    在Java中可以通过System.currentTimeMillis()或者System.nanoTime() (JDK>=5.0) 方法获得当前的时间的精确值。但是通过阅读Javadoc,我们发现这两个方法并不一定保证得到你所期望的精度。先来看System.currentTimeMillis():
Returns the current time in milliseconds. Note that while the unit of time of
the return value is a millisecond, the granularity of the value depends on the
underlying operating system and may be larger. For example, many operating
systems measure time in units of tens of milliseconds.
诚如上面所说返回值的粒度依赖于底层操作系统,那么它在不同的平台上到底能提供是么样的精度,是否像函数名所写的那样真正

确到1毫秒呢?看下面一段测试程序:
public class ClockAccuracyTest {
    public static void main(String args[]) {
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:SSS");
        int size = 4000000;
        // create an array to hold millisecond times
        // and loop to capture them
        long times[] = new long[size];
        for (int i = 0; i < size; i++) {
            times[i] = System.currentTimeMillis();
        }
        // now display the unique times
        long time = times[0];
        long previousTime = times[0];
        long count = 0;
        Set<Long> deltas = new HashSet<Long>();       
        long delta = 0;
        long minDelta = Long.MAX_VALUE;
        long maxDelta = Long.MIN_VALUE;
    &


相关文档:

基于Java的简易播放器

 在Java Aplication中实现的简易播放器。来源于胡巧多主编的《Java程序设计案例教程》
我试运行过了,其中的 “听海.wav”,“一定要爱你.wav”音频文件要放在class所在的文件夹中,且只支持wav格式
源代码:
import java.applet.Applet;
import java.applet.AudioClip;
import javax.swing.* ......

《java语言程序设计(一)》2009年自学考试大纲第2章

《java语言程序设计(一)》2009年自学考试大纲第2章
www.wesiedu.com   2009-5-5   在线模拟考场
第2章 运算和语句
(一)课程内容
2.1 数据运算
2.1.1 赋值运算
2.1.2算术运算
2.1.3自增和自减运算
2.1.4关系运算
2.1.5逻辑运算
2.1.6条件运算
2.1.7其他运算
2.2语句
2.2.1基本语句
2.2 ......

《java语言程序设计(一)》2009年自学考试大纲第3章

《java语言程序设计(一)》2009年自学考试大纲第3章
www.wesiedu.com   2009-5-5   在线模拟考场
第3章 面向对象编程基础
(一)课程内容
3.1 面向对象的基本概念
3.2 Java的类和对象
3.2.1 类
3.2.2对象
3.2.3实例变量和类变量
3.2.4实例方法和类方法
3.2.5访问权限
3.2.6继承
3.2.7 Java ......

Java调用C#的WebService实例三(实际应用)

/*
   本段代码在公司项目中实际远程调用第三方公司提供的C#开发WebService的示例
*/
/**
  * 登录游戏
  *
  * @param paramPN
  * @param paramTerraceID
  * @param paramSvrID
  */
 private String loginGame(String paramPN, HttpServletRequest req){
&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号