Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

java»ñÈ¡Ô­×ÓÖÓʱ¼ä²¢¸Ä±ä±¾µØʱ¼ä

 package dtm.tools;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* SyncTime »ñÈ¡Ô­×ÓÖÓµÄʱ¼ä£¬²¢ÉèÖÃΪϵͳʱ¼ä
* @author Administrator
*/
public class SyncTime {
private static int sleepMinutes = 0;
private static final long EPOCH_OFFSET_MILLIS;
private static final String[] hostName = {"time-a.nist.gov", "time-nw.nist.gov", "time.nist.gov"};
static {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
// JavaʹÓõIJÎÕÕ±ê×¼ÊÇ1970Ä꣬¶øʱ¼ä·þÎñÆ÷·µ»ØµÄÃëÊÇÏ൱1900ÄêµÄ£¬ËãÒ»ÏÂÆ«ÒÆ
calendar.set(1900, Calendar.JANUARY, 1, 0, 0, 0);
EPOCH_OFFSET_MILLIS = Math.abs(calendar.getTime().getTime());
}
public static void main(String[] args) {
GetWebTime();
}
private static Date getNetDate(String hostName) {
Date date = null;
long result = 0;
try {
Socket socket = new Socket(hostName, 37);
BufferedInputStream bis = new BufferedInputStream(socket.getInputStream(),
socket.getReceiveBufferSize());
int b1 = bis.read();
int b2 = bis.read();
int b3 = bis.read();
int b4 = bis.read();
if ((b1 | b2 | b3 | b3) < 0) {
return null;
}
result = (((long) b1) << 24) + (b2 << 16) + (b3 << 8) + b4;
date = new Date(result * 1000 - EPOCH_OFFSET_MILLIS);
socket.close();
} catch (UnknownHostException ex) {
Logger.getLogger(SyncTime.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {


Ïà¹ØÎĵµ£º

javaÈëÃÅ

 Javaѧϰ´ÓÈëÃŵ½¾«Í¨ 
Ò»¡¢ JDK (Java Development Kit) 
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJ ......

ʹÓÃMaven¿ª·¢JavaÏîÄ¿

ÆäʵʹÓÃmavenÒѾ­ºÜ¾ÃÁË£¬´ÓÔçÆÚµÄ1.0.1µ½ÏÖÔÚµÄ2.0.6£¬Æäʵ¶ÔÓÚÒ»°ãÏîÄ¿¿ª·¢£¬³£ÓõÄÒ²¾ÍÊÇ´´½¨ÏîÄ¿(Create)¡¢¹¹½¨(Build)¡¢²âÊÔ(Test)¡¢·¢²¼(Release)¡£±¾ÎIJ¢²»ÊǹØÓÚmavenÈçºÎʹÓõÄÏêϸ½éÉÜ£¬¶øÖ»ÊÇÔÚʵ¼ÊÏîÄ¿¿ª·¢ÖеÄһЩ³£ÓûÒÔ¼°Ïà¹Ø²å¼þµÄʹÓÃ×ܽᣬÈç¹ûÄã¶ÔÓÚmavenÉв»Á˽⣬¿ÉÒÔÏÈÔÚ¹Ù·½ÍøÕ¾[Maven'site]¹ä¹ ......

¼ÆËã»ú¶þ¼¶java¸¨µ¼£ºÊÕ¼¯µÄÕýÔò±í´ïʽ

http://campus.chsi.com.cn/xy/com/200909/20090923/33536175.html 
¼ÆËã»ú¶þ¼¶java¸¨µ¼£ºÊÕ¼¯µÄÕýÔò±í´ïʽ
À´Ô´£º¿¼ÊÔ´ó     2009Äê09ÔÂ23ÈÕ 10:50
¡¡¡¡ÕýÔò±í´ïʽÊǸöºÜ²»´íµÄ¶«Î÷£¬¿ÉÒÔÈÃÄãʹÓÃÖ¸¶¨µÄģʽȥ·ÖÎö×Ö·û´®£¬µ±ÄêPerlͨ¹ýÌṩÁËÀàËÆÕýÔò±í´ïʽµÄ¹¦ÄܺóÀ´¶À²½ÎäÁÖ£¬ºÃ²»·ç¹â(²»¹ý ......

Java Socket ³¤Á¬½ÓͨÐÅ

 ×î½üÏîÄ¿ÖÐÓиöÐèÇó£¬ÒªÓÃSocketʵÏÖ³¤Á¬½Ó£¬²¢ÇÒÔÚͨÐŹý³ÌÖÐÒª»¥ÎªserverºÍclient£¬¼´ÔÚÒ»¸öÁ¬½ÓÖУ¬¼ÈÄܹ»·¢ËÍÏûÏ¢£¬£¨´Ëʱ×÷Ϊ¿Í»§¶Ë£©£¬ÓÖÒªÄܹ»½ÓÊÕÏûÏ¢£¨´Ëʱ×÷Ϊserver¶Ë£©£¬Ñо¿ÁËÏ£¬ÊµÏÖ·½Ê½ÈçÏ£º
Ò»¡¢·¢ËÍÏûϢʱ½¨Á¢Á¬½Ó£¬¹¹½¨Í¨µÀ¡£
Socket socket = new Socket();
SocketAddress endpoint = new In ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ