獲取當前時間的例子總結

2022-04-05 13:32:34 字數 698 閱讀 5702

1.

2.var mydate = new date();

mydate.getyear();       //獲取當前年份(2位)

mydate.getfullyear();   //獲取完整的年份(4位,1970-????)

mydate.getmonth();      //獲取當前月份(0-11,0代表1月)

mydate.getdate();       //獲取當前日(1-31)

mydate.getday();        //獲取當前星期x(0-6,0代表星期天)

mydate.gettime();       //獲取當前時間(從1970.1.1開始的毫秒數)

mydate.gethours();      //獲取當前小時數(0-23)

mydate.getminutes();    //獲取當前分鐘數(0-59)

mydate.getseconds();    //獲取當前秒數(0-59)

mydate.getmilliseconds();   //獲取當前毫秒數(0-999)

mydate.tolocaledatestring();    //獲取當前日期

var mytime=mydate.tolocaletimestring();    //獲取當前時間

mydate.tolocalestring( );       //獲取日期與時間 

獲取當前時間

獲取日期 時間 datetime.now.tostring 2008 9 4 20 02 10 datetime.now.tolocaltime tostring 2008 9 4 20 12 12 獲取日期 datetime.now.tolongdatestring tostring 2008年9...

獲取當前時間

直接上可以執行的 檔案 獲取當前時間.cpp 方案 time 優點 僅使用c標準庫 缺點 只能精確到秒級 include time.h include stdio.h int main void 方案二getlocaltime 優點 能精確到毫秒級 缺點 使用了windows api include...

獲取當前時間

使用函式 date 實現 顯示的格式 年 月 日 小時 分鐘 妙 相關時間引數 a am 或是 pm a am 或是 pm d 幾日,二位數字,若不足二位則前面補零 如 01 至 31 d 星期幾,三個英文本母 如 fri f 月份,英文全名 如 january h 12 小時制的小時 如 01 至...