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

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

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

    java Source

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      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 閱讀(1645) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲日韩在线观看免费视频| 亚洲人成色99999在线观看| 久久www免费人成看国产片| 国产男女猛烈无遮挡免费视频网站 | 亚洲一区二区三区在线| 13一14周岁毛片免费| 亚洲欧洲精品在线| 日本zzzzwww大片免费| 亚洲色欲色欲www| 毛片免费在线观看网站| 亚洲爆乳无码精品AAA片蜜桃| 日韩免费福利视频| 曰批全过程免费视频免费看| 亚洲日韩国产精品乱| a毛片在线免费观看| 亚洲黄色在线观看网站| 97在线观免费视频观看| 亚洲妇女无套内射精| 亚洲第一页综合图片自拍| aaa毛片视频免费观看| 亚洲av色影在线| 免费人成在线视频| 污网站在线观看免费| 亚洲精品国产美女久久久| 久久成人国产精品免费软件| 亚洲日韩国产二区无码| 亚洲偷自拍拍综合网| 99ee6热久久免费精品6| 亚洲精华国产精华精华液好用 | 婷婷亚洲天堂影院| 免费在线观看日韩| 国产成人无码免费网站| 亚洲视屏在线观看| 国产精品黄页在线播放免费| a级毛片高清免费视频| 亚洲一级免费毛片| 国产亚洲AV手机在线观看| 成人免费在线看片| 五月天婷婷免费视频| 免费jjzz在在线播放国产| 在线观看免费无码专区|