以下是一個使用VC++時間處理類別CTime的範例
int main(int argc, TCHAR* argv[]) { CTime cTime = CTime::GetCurrentTime(); printf("Year : %d\n", cTime.GetYear()); printf("Month : %d\n", cTime.GetMonth()); printf("Day : %d\n", cTime.GetDay()); printf("Hour : %d\n", cTime.GetHour()); printf("Minute : %d\n", cTime.GetMinute()); printf("Second : %d\n", cTime.GetSecond()); printf("Time : %d\n", cTime.GetTime()); return 1; }執行結果
以下是一個使用JavaScript時間處理函數的範例
<html> <head> <title>JavaScript Test Date Function</title> <script type="text/javascript"> function run() { var CurrentTime = new Date(); document.write("Year : " + (CurrentTime.getYear() + 1900) + "<br>") document.write("Month : " + (CurrentTime.getMonth() + 1) + "<br>") document.write("Date : " + CurrentTime.getDate() + "<br>") document.write("Hours : " + CurrentTime.getHours() + "<br>") document.write("Minutes : " + CurrentTime.getMinutes() + "<br>") document.write("Seconds : " + CurrentTime.getSeconds() + "<br>") document.write("Time : " + CurrentTime.getTime() + "<br>") } </script> </head> <body onload = run();> </body> </html>執行結果
兩者的差異
VC++
|
JavaScript
|
|
Time
|
Second
|
Millisecond
|
Year
|
不加1900
|
需加1900
|
Month
|
以1為起點,範圍1~12
|
以0為起點,範圍0~11
|
沒有留言:
張貼留言