天天看點

網絡擷取中原標準時間和系統時間

public static void main(String[] args) throws Exception {

       URL url=new URL("http://www.bjtime.cn");//取得資源對象

       URLConnection uc=url.openConnection();//生成連接配接對象

       uc.connect(); //發出連接配接

       long ld=uc.getDate(); //取得網站日期時間(時間戳)

       Date date=new Date(ld); //轉換為标準時間對象

       //分别取得時間中的小時,分鐘和秒,并輸出

       System.out.print(date.getHours()+"時"+date.getMinutes()+"分"+date.getSeconds()+"秒");

 }