<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java Source

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks
    import java.io.InputStream;
    import java.net.Socket;

    /**
     * 
     * 
    @author ray (justinlei@gmail.com)
     * @date 2009-8-27
     * 
    @version 1.0
     
    */
    public class TimeUtil {
        
    public static final int DEFAULT_PORT = 37;
        
    public static final String DEFAULT_HOST = "time-nw.nist.gov";
        
    private TimeUtil() {
        };

        
    public static long currentTimeMillis(Boolean sync) {
            
    if (sync != null && sync.booleanValue() != true)
                
    return System.currentTimeMillis();
            
    try {
                
    return syncCurrentTime();
            } 
    catch (Exception e) {
                
    return System.currentTimeMillis();
            }
        }

        
    public static long syncCurrentTime()  throws Exception {
            
    // The time protocol sets the epoch at 1900,
            
    // the java Date class at 1970. This number
            
    // converts between them.
            long differenceBetweenEpochs = 2208988800L;

            
    // If you'd rather not use the magic number uncomment
            
    // the following section which calculates it directly.

            
    /*
             * TimeZone gmt = TimeZone.getTimeZone("GMT"); Calendar epoch1900 =
             * Calendar.getInstance(gmt); epoch1900.set(1900, 01, 01, 00, 00, 00);
             * long epoch1900ms = epoch1900.getTime().getTime(); Calendar epoch1970
             * = Calendar.getInstance(gmt); epoch1970.set(1970, 01, 01, 00, 00, 00);
             * long epoch1970ms = epoch1970.getTime().getTime();
             * 
             * long differenceInMS = epoch1970ms - epoch1900ms; long
             * differenceBetweenEpochs = differenceInMS/1000;
             
    */

            InputStream raw 
    = null;
            
    try {
                Socket theSocket 
    = new Socket(DEFAULT_HOST, DEFAULT_PORT);
                raw 
    = theSocket.getInputStream();

                
    long secondsSince1900 = 0;
                
    for (int i = 0; i < 4; i++) {
                    secondsSince1900 
    = (secondsSince1900 << 8| raw.read();
                }
                
    if (raw != null)
                    raw.close();
                
    long secondsSince1970 = secondsSince1900 - differenceBetweenEpochs;
                
    long msSince1970 = secondsSince1970 * 1000;
                
    return msSince1970;
            } 
    catch (Exception e) {
                
    throw new Exception(e);
            }
        }
    }
    posted on 2011-12-04 02:54 JustinLei 閱讀(1639) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产亚洲福利一区二区免费看| 91亚洲国产成人久久精品| 国产v精品成人免费视频400条| 久久国产精品免费一区二区三区| 亚洲色偷偷综合亚洲AV伊人蜜桃| 久久久久亚洲精品日久生情| 国产成人99久久亚洲综合精品| 在线观看免费污视频| 最近免费2019中文字幕大全| a级毛片100部免费观看| 免费一级毛片在线播放视频免费观看永久 | 中文字幕在线成人免费看| 亚洲国产成人久久一区二区三区| 亚洲精品中文字幕乱码影院| 亚洲国产精品无码久久久不卡| 亚洲精品无码久久久久AV麻豆| 午夜一区二区免费视频| 欧美三级在线电影免费| 亚洲免费视频播放| 美丽姑娘免费观看在线观看中文版| 中文字幕免费在线看电影大全| 亚洲一区二区三区免费| 色多多www视频在线观看免费| 国产青草亚洲香蕉精品久久| 亚洲精品无码av中文字幕| 亚洲精品国产日韩| 亚洲制服丝袜中文字幕| 国产精品亚洲专区在线观看| 亚洲午夜精品在线| 亚洲国产精品线观看不卡| 亚洲成综合人影院在院播放| 亚洲成a人片毛片在线| 亚洲福利视频网址| 亚洲国产精品成人精品小说| 亚洲国产成人91精品| 亚洲欧洲精品国产区| 亚洲中字慕日产2020| 中文有码亚洲制服av片| 亚洲乱亚洲乱妇无码| 无码色偷偷亚洲国内自拍| 免费国产草莓视频在线观看黄|