C#Datetime转换字符串格式⼤全原始⽇期:2021/2/23 10:42:18
DateTime date = DateTime.Now;
转换⽅式备注值
ToString()2021/2/23 10:42:18 ToLongDateString()长⽇期2021年2⽉23⽇ToLongTimeString()长时间10:42:18
ToShortDateString()短⽇期2021/2/23
ToShortTimeString()短时间10:42
ToString("yyyy - MM - dd hh: mm:ss")年⽉⽇时分秒2021-02-23 10:42:18
ToString("yyyy/MM/dd")短⽇期2021/02/23
ToString(d)2021/2/23
ToString(D)2021年2⽉23⽇
ToString(f)2021年2⽉23⽇ 10:42
ToString(F)2021年2⽉23⽇ 10:42:18
ToString(g)2021/2/23 10:42
ToString(G)2021/2/23 10:42:18
ToString(M)2⽉23⽇
ToString(O)2021-02-23T10:42:18.3623803+08:00 ToString(R)Tue, 23 Feb 2021 10:42:18 GMT ToString(s)2021-02-23T10:42:18
ToString(t)10:42
ToString(T)10:42:18
ToString(u)2021-02-23 10:42:18Z
ToString(U)2021年2⽉23⽇ 2:42:18
ToString(Y)2021年2⽉
ToString(dd)23
ToString(ddd)周⼆
ToString(dddd)星期⼆
ToString(ff)36
ToString(fff)362
ToString(ffff)3623
ToString(fffff)36238
ToString(ffffff)362380
ToString(fffffff)3623803
ToString(FF)36
ToString(FFF)362
ToString(FFFF)3623
ToString(FFFFF)36238
ToString(FFFFFF)36238
ToString(FFFFFFF)3623803
ToString(gg)公元
ToString(hh)10
ToString(HH)10
ToString(mm)42
ToString(m)2⽉23⽇
ToString(MM)02
ToString(MMM)2⽉
ToString(MMMM)⼆⽉
ToString(ss)18
ToString(tt)上午
ToString(y)2021年2⽉
ToString(yy)21
ToString(yyy)2021
ToString(yyyy)2021
ToString(yyyyy)02021
转换⽅式备注值
时间分隔符: / -
ToBinary().ToString()-8585875587471152005 ToFileTime().ToString()132585217383623803 ToFileTimeUtc().ToString()132585217383623803 ToLocalTime().ToString()2021/2/23 10:42:18 ToOADate().ToString()44250.4460458565 ToUniversalTime().ToString()2021/2/23 2:42:18
Add(new TimeSpan(1, 1, 1)).ToString()2021/2/23 11:43:19
Add(new TimeSpan()).ToString()2021/2/23 10:42:18
Add(new TimeSpan(1)).ToString()2021/2/23 10:42:18
Add(new TimeSpan(1, 1, 1, 1)).ToString()2021/2/24 11:43:19
string转date的方法
Add(new TimeSpan(1, 1, 1, 1, 1)).ToString()2021/2/24 11:43:19
AddDays(1).ToString()2021/2/24 10:42:18 AddHours(1).ToString()2021/2/23 11:42:18 AddMilliseconds(1).ToString()2021/2/23 10:42:18 AddMinutes(1).ToString()2021/2/23 10:43:18 AddMonths(1).ToString()2021/3/23 10:42:18 AddSeconds(1).ToString()2021/2/23 10:42:19
AddTicks(1).ToString()2021/2/23 10:42:18 AddYears(1).ToString()2022/2/23 10:42:18
Date.ToString()2021/2/23 0:00:00
Day.ToString()23
DayOfWeek.ToString()Tuesday
DayOfYear.ToString()54
Hour.ToString()10
Kind.ToString()Local
Millisecond.ToString()362
Minute.ToString()42
Month.ToString()2
Second.ToString()18
Ticks.ToString()637496737383623803 TimeOfDay.ToString()10:42:18.3623803
Year.ToString()2021
string.Format("{0:d}", dateTime))2021/2/23
string.Format("{0:D}", dateTime))2021年2⽉23⽇
string.Format("{0:f}", dateTime))2021年2⽉23⽇ 10:42
string.Format("{0:F}", dateTime))2021年2⽉23⽇ 10:42:18 string.Format("{0:g}", dateTime))2021/2/23 10:42
string.Format("{0:G}", dateTime))2021/2/23 10:42:18
string.Format("{0:M}", dateTime))2⽉23⽇
string.Format("{0:R}", dateTime))Tue, 23 Feb 2021 10:42:18 GMT string.Format("{0:s}", dateTime))2021-02-23T10:42:18
string.Format("{0:t}", dateTime))10:42
string.Format("{0:T}", dateTime))10:42:18
string.Format("{0:u}", dateTime))2021-02-23 10:42:18Z string.Format("{0:U}", dateTime))2021年2⽉23⽇ 2:42:18 string.Format("{0:Y}", dateTime))2021年2⽉
string.Format("{0}", dateTime))2021/2/23 10:42:18
string.Format("{0:yyyyMMddHHmmssffff}", dateTime))202102231042183623

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。