【www.gdgbn.com--php函数】


c#日期函数所有样式大全

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;
(变量可用中文)2、int32.parse(变量) int32.parse("常量")
字符型转换 转为32位数字型
1.9 取中文日期显示——年月日时分
string stry=currenttime.tostring("f"); //不显示秒
1.10 取中文日期显示_年月
string strym=currenttime.tostring("y");
1.11 取中文日期显示_月日
string strmd=currenttime.tostring("m");
1.12 取当前年月日,格式为:2003-9-23
string strymd=currenttime.tostring("d");
1.13 取当前时分,格式为:14:24
string strt=currenttime.tostring("t");
 label1.text =  string.format("{0:d}",dt);//2005-11-5
   label2.text =  string.format("{0}",dt);//2005年11月5日
   label3.text =  string.format("{0:f}",dt);//2005年11月5日 14:23
   label4.text =  string.format("{0:f}",dt);//2005年11月5日 14:23:23
   label5.text =  string.format("{0:g}",dt);//2005-11-5 14:23
   label6.text =  string.format("{0:g}",dt);//2005-11-5 14:23:23
   label7.text =  string.format("{0:m}",dt);//11月5日
   label8.text =  string.format("{0:r}",dt);//sat, 05 nov 2005 14:23:23 gmt
   label9.text =  string.format("{0:s}",dt);//2005-11-05t14:23:23
   label10.text = string.format("{0:t}",dt);//14:23
   label11.text = string.format("{0:t}",dt);//14:23:23
   label12.text = string.format("{0:u}",dt);//2005-11-05 14:23:23z
   label13.text = string.format("{0:u}",dt);//2005年11月5日 6:23:23
   label14.text = string.format("{0:y}",dt);//2005年11月
   label15.text = string.format("{0}",dt);//2005-11-5 14:23:23
   label16.text = string.format("{0:yyyymmddhhmmssffff}",dt);

本文来源:http://www.gdgbn.com/jiaocheng/29458/