C 中對時間的操作

2021-04-27 01:16:05 字數 1338 閱讀 2981

1、datetime 數字型

system.datetime currenttime=new system.datetime();

1.1 取當前年月日時分秒

currenttime=system.datetime.now;

1.2 取當前年

int 年=currenttime.year;

1.3 取當前月

int 月=currenttime.month;

1.4 取當前日

int 日=currenttime.day;

1.5 取當前時

int 時=currenttime.hour;

1.6 取當前分

int 分=currenttime.minute;

1.7 取當前秒

int 秒=currenttime.second;

1.8 取當前毫秒

int 毫秒=currenttime.millisecond;

(變數可用中文)  

1.9 取中文日期顯示——年月日時分

string stry=currenttime.tostring("f"); //不顯示秒

1.10 取中文日期顯示_年月

string strym=currenttime.tostring("y");

1.11 取中文日期顯示_月日

string strmd=currenttime.tostring("m");

1.12 取中文年月日

string strymd=currenttime.tostring("d");

1.13 取當前時分,格式為:14:24

string strt=currenttime.tostring("t");

1.14 取當前時間,格式為:2003-09-23t14:46:48

string strt=currenttime.tostring("s");

1.15 取當前時間,格式為:2003-09-23 14:48:30z

string strt=currenttime.tostring("u");

1.16 取當前時間,格式為:2003-09-23 14:48

string strt=currenttime.tostring("g");

1.17 取當前時間,格式為:tue, 23 sep 2003 14:52:40 gmt

string strt=currenttime.tostring("r");

1.18獲得當前時間 n 天後的日期時間

datetime newday = datetime.now.adddays(100);

C 對時間的操作

獲取當前星期的開始日期和結束日期 private void timebe out string bdate,out string edate else if firstday.dayofweek dayofweek.monday else if firstday.dayofweek dayofwee...

js對時間的操作

獲取當前時間 var mydate new date 獲取時間中的年月日時分秒 mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲...

Object C中對時間的處理

一般有獲取具體的年月日和星期,兩個不同時間的差,某一天的前一天或後一天等 在這裡我只介紹獲取具體的年月日和星期,及某一天的前一天或後一天的方法 對時間的處理一般都會用到nsdate類和nscalendar類兩個類 獲取當前的時間是 nsdate nowdate nsdate date 獲取具體的年月...