2013年9月25日 星期三

Java 查詢可用時區參數與設定時區

    Java 中可以透過 TimeZone 物件來查詢、設定 有關時區資訊。

查詢目前使用的時區:
TimeZone.getDefault().getID(); // Asia/Taipei
TimeZone.getDefault().getDisplayName(); // friendly name ex: 台灣標準時間

設定時區:
TimeZone tx = TimeZone.getTimeZone("Indian/Cocos"); // "Indian/Cocos" 就是 TimeZone ID
TimeZone.setDefault(tx);

列出可用時區:
String [] ids = TimeZone.getAvailableIDs();
for (String timezone : ids) {
    System.out.println(timezone + " " + 
          TimeZone.getTimeZone(timezone).getDisplayName());
}

   如果要取得目前日期時間可以透過 Calendar 物件取的相關訊息:
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
int month = now.get(Calendar.MONTH);
int day = now.get(Calendar.DAY_OF_MONTH);
int year = now.get(Calendar.YEAR);
System.out.printf("現在是 %d/%d/%d %02d:%02d:%02d", 
    year, (month+1), day, hour, minute, second);

    要注意的是,Calendar 物件類別中的 MONTH 是用 0 到 11 來到表 1 月到 12 月,所以取得的數值要加 1 才會顯示正確。
 
    當你發現上面顯示的日期時間與你的電腦不符時,有可能是 Java 解譯器用錯時區設定;當 Java 解譯器不曉得目前的預設時區的話,會直接使用格林威治時間。

[相關資料]
[Java] 日期方法 (Date method)

懸置物件(dangling object)、懸置指標(dangling pointer)、懸置引用(dangling reference)

下面解釋來源: 程式語言結構 1

(1)懸置物件(dangling object):一個仍然存放資訊的記憶體空間,可是已沒有辦法可存取這個空間,則此空間便被稱為懸置物件。

(2)懸置指標(dangling pointer):懸置指標意謂指標指到一個不存在任何有意義資訊的記憶體空間。

(3)懸置引用(dangling reference):懸置引用意謂指標變數指到一個已經不存在的記憶體空間。如Pascal語言中,x是一個指標變數,當執行了dispose(x)後,(即將x所佔用的記憶體空間歸還給系統),若想引用x,則將造成懸置引用現象。

根據 Object-Oriented Programming in C++ 的解釋如下:

Dangling pointer
   Pointer point to a heap-dynamic variable that has been de-allocated.

Dangling reference
   Pointers that refer to something that no longer there and also occurs when a function return a pointer point to local variable.


[關鍵字]
dangling object dangling pointer dangling reference

[相關參考網站]

網路資源搜尋

Filesonic Hotfile Search - 可以找尋 影音及應用程式的搜尋引擎,但是中文沒有支援,所以你要搜尋的影片必須知道它的英文翻譯才行,該search engine 主要搜尋 hotfile.com 與 filesonic.com 檔案伺服器。

ShareDigger - File Search Engine - 可以搜尋 4filehosting.com、 Badongo.com、Depositfiles.com、Filefront.com、iFolder.ru、Megashares.com、Megaupload.com、Multiply.com、Rapidshare.com、Rapidshare.de、Rapidsharing.com、Rapidupload.com、Sendspace.com、TurboUpload.com、zshare.net網站上面所分享的檔案。

FileCrop - Search and Download Rapidshare Megaupload and Hotfile Files

Global FTP Search Engine: Global File Search Engine

YunFile- 網路檔案上傳伺服器,只能上傳檔案分享給其他人,沒有搜尋的功能,但是還是可以透過 Google來搜尋該伺服器目前有哪些分享的檔案。

http://hotfile.com/

4shared.com - 免費文件分享及儲存 有自己的資源搜尋引擎。讚!!

[Keyword]
File search engine

[相關文章]
多個免費檔案分流服務,讓你上傳一次就能儲存到一堆免費空間!
免費網路硬碟比一比
網路硬碟 | ㊣軟體玩家
【下載】: 免費網路硬碟空間50g【分享】 - yam天空部落
雲端大戰,6大免費網路硬碟誰最好用(上) | T客邦 - 我只推薦好東西
雲端大戰,6大免費網路硬碟誰最好用(下) | T客邦 - 我只推薦好東西

網路開放課程鏈結


麻省理工學院「開放式課程網頁」首頁

http://www.myoops.org/twocw/mit/index.htm

國立交通大學OpenCourseWare開放式課程
http://ocw.nctu.edu.tw/index.php 

哈佛進修學院遠距教育計劃
http://www.myoops.org/twocw/harvard/welcome/index.htm 

約翰霍普金斯大學彭博公共衛生學院開放式課程
http://www.myoops.org/twocw/jhsph/index.htm

日本開放式課程網頁聯盟
http://www.myoops.org/twocw/jocw/index.htm

台灣開放式課程網頁聯盟
http://www.tocwc.org.tw/

TBSCTS [專科]程式語言Youtube影片
http://www.youtube.com/view_play_list?p=06810CD71A86FACC

C 入門教學Youtube影片
http://www.youtube.com/view_play_list?p=0B6BF05869177563

中小企業網路大學校-數位學習
http://www.smelearning.org.tw/

我要自学网
http://www.51zxw.net/

MyOOPS開放式課程
http://www.myoops.org/main.php

C++ Tutorial by Zaychenok
http://www.youtube.com/watch?v=H1gV4JQI7OI&feature=BFa&list=PL0D836394D2FDDDB6&index=1

XoaX.net Video Tutorials
http://xoax.net/