c#日期转换周几_C#日期格式转换大全

0).ToString();//2005-11-5 13:47:04

Label10.Text = dt.CompareTo(dt).ToString();//0

Label11.Text = dt.Add(?).ToString();//问号为一个时间段

Label1.Text = dt.Equals("2005-11-6 16:11:04").ToString();//False

Label2.Text = dt.Equals(dt).ToString();//True

Label3.Text = dt.GetHashCode().ToString();//1474088234

Label4.Text = dt.GetType().ToString();//System.DateTime

Label5.Text = dt.GetTypeCode().ToString();//DateTime

Label1.Text = dt.GetDateTimeFormats('s')[0].ToString();//2005-11-05T14:06:25

Label2.Text = dt.GetDateTimeFormats('t')[0].ToString();//14:06

Label3.Text = dt.GetDateTimeFormats('y')[0].ToString();//2005年11月

Label4.Text = dt.GetDateTimeFormats('D')[0].ToString();//2005年11月5日

Label5.Text = dt.GetDateTimeFormats('D')[1].ToString();//2005 11 05

Label6.Text = dt.GetDateTimeFormats('D')[2].ToString();//星期六 2005 11 05

Label7.Text = dt.GetDateTimeFormats('D')[3].ToString();//星期六 2005年11月5日

Label8.Text = dt.GetDateTimeFormats('M')[0].ToString();//11月5日

Label9.Text = dt.GetDateTimeFormats('f')[0].ToString();//2005年11月5日 14:06

Label10.Text = dt.GetDateTimeFormats('g')[0].ToString();//2005-11-5 14:06

Label11.Text = dt.GetDateTimeFormats('r')[0].ToString();//Sat, 05 Nov 2005 14:06:25 GMT

Label1.Text = string.Format("{0:d}",dt);//2005-11-5

Label2.Text = string.Format("{0:D}",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);

C#比较两时间大小

1、比较时间大小的实验 string st1="12:13"; string st2="14:14"; DateTime dt1=Convert.ToDateTime(st1); DateTime dt2=Convert.ToDateTime(st2); DateTime dt3=DateTime.Now; if(DateTime.Compare(dt1,dt2)&gt0) msg.Text=st1+"&gt"+st2; else msg.Text=st1+"&lt"+st2; msg.Text+="\r\n"+dt1.ToString(); if(DateTime.Compare(dt1,dt3)&gt0) msg.Text+="\r\n"+st1+"&gt"+dt3.ToString(); else msg.Text+="\r\n"+st1+"&lt"+dt3.ToString();

2、计算两个时间差值的函数,返回时间差的绝对值: private string DateDiff(DateTime DateTime1,DateTime DateTime2) { string dateDiff=null; try { TimeSpan ts1=new TimeSpan(DateTime1.Ticks);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值