C 時間格式的轉換!

2021-06-08 10:54:35 字數 3458 閱讀 5817

1:

時間格式轉換

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:

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

1.14 

當前時間,格式為:

2003-09-23

t14: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);

1.19

將2006-8-7 9:13

:45------>2006/08/07 09:13

lblnow.text =system.datetime.now.tostring("yyyy/mm/dd hh:mm").replace("-","/");

string data1=convert.todatetime(dtpkfrom.text.trim()).tostring("yyyy-mm-dd ");

string data2=convert.todatetime(dtpkto.text.trim()).tostring("yyyy-mm-dd ");

以下內容**在此多謝博主!

datetime.now=2009-7-16 5:20:56

//今天

datetime.now.date.tostring();

"2009-7-16 0:00:00"

//起始日期

datetime.now.date.adddays(-(int)(datetime.now.dayofweek)+1).tostring();

datetime.now.date.adddays(7-(int)(datetime.now.dayofweek)).tostring();

//月起始日期

new datetime(datetime.now.year,datetime.now.month,1).tostring();

new   datetime(datetime.now.date.year,datetime.now.date.month,datetime.daysinmonth(datetime.now.date.year,datetime.now.date.month)).tostring();

"2009-7-31 0:00:00"

//年起始日期

new   datetime(datetime.now.date.year,1,1).tostring();

new   datetime(datetime.now.date.year,12,datetime.daysinmonth(datetime.now.date.year,datetime.now.date.month)).tostring();

c 時間格式轉換

好記性不如爛筆頭 把今天遇到的時間轉換的問題記錄下來 tostring 轉換格式 1 string time datetime.now.tostring yyyy mm dd 得到 2013 09 09 注意 yyyy必須為小寫 否則會顯示為 yyyy 09 09 mm必須為大寫否則顯示為 2013...

時間格式轉換 時間戳的轉換

1 thu mar 07 2019 12 00 00 gmt 0800 中國標準時間 轉換為 2019 03 07 12 00 00 const d new date thu mar 07 2019 12 00 00 gmt 0800 中國標準時間 const resdate d.getfullye...

時間格式的轉換

string型別轉為date型別 string time 2010 10 19 15 22 00 date d timestamp.valueof time 注意 當time中月份和天數小於10時會報錯 string型別格式化返回string型別 string time 2010 10 19 15 ...