熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

c# string.Format格式化日期

2022-06-13   來源: .NET編程 

  DateTime dt = DateTimeNow;

  LabelText = dtToString();// ::

  LabelText = dtToFileTime()ToString();//

  LabelText = dtToFileTimeUtc()ToString();//

  LabelText = dtToLocalTime()ToString();// ::

  LabelText = dtToLongDateString()ToString();//*

  LabelText = dtToLongTimeString()ToString();//::

  LabelText = dtToOADate()ToString();//

  LabelText = dtToShortDateString()ToString();//

  LabelText = dtToShortTimeString()ToString();//:

  LabelText = dtToUniversalTime()ToString();// ::

  ? ::

  LabelText = dtYearToString();//

  LabelText = dtDateToString();// ::

  LabelText = dtDayOfWeekToString();//Saturday

  LabelText = dtDayOfYearToString();//

  LabelText = dtHourToString();//

  LabelText = dtMillisecondToString();//

  LabelText = dtMinuteToString();//

  LabelText = dtMonthToString();//

  LabelText = dtSecondToString();//

  LabelText = dtTicksToString();//

  LabelText = dtTimeOfDayToString();//::

  LabelText = dtToString();// ::

  LabelText = dtAddYears()ToString();// ::

  LabelText = dtAddDays()ToString();// ::

  LabelText = dtAddHours()ToString();// ::

  LabelText = dtAddMilliseconds()ToString();// ::

  LabelText = dtAddMonths()ToString();// ::

  LabelText = dtAddSeconds()ToString();// ::

  LabelText = dtAddMinutes()ToString();// ::

  LabelText = dtAddTicks()ToString();// ::

  LabelText = dtCompareTo(dt)ToString();//

  //LabelText = dtAdd(?)ToString();//問號為一個時間段

  LabelText = dtEquals( ::)ToString();//False

  LabelText = dtEquals(dt)ToString();//True

  LabelText = dtGetHashCode()ToString();//

  LabelText = dtGetType()ToString();//SystemDateTime

  LabelText = dtGetTypeCode()ToString();//DateTime

  LabelText = dtGetDateTimeFormats(s)[]ToString();//T::

  LabelText = dtGetDateTimeFormats(t)[]ToString();//:

  LabelText = dtGetDateTimeFormats(y)[]ToString();//

  LabelText = dtGetDateTimeFormats(D)[]ToString();//*

  LabelText = dtGetDateTimeFormats(D)[]ToString();//

  LabelText = dtGetDateTimeFormats(D)[]ToString();//星期六

  LabelText = dtGetDateTimeFormats(D)[]ToString();//星期六 *

  LabelText = dtGetDateTimeFormats(M)[]ToString();//*

  LabelText = dtGetDateTimeFormats(f)[]ToString();//* :

  LabelText = dtGetDateTimeFormats(g)[]ToString();// :

  LabelText = dtGetDateTimeFormats(r)[]ToString();//Sat Nov :: GMT

  或者dtToString(yyyy年MM月dd*);//*

  dtToString(yyyyMMdd);//*

  以此類推……

  LabelText =? stringFormat(:d}dt);//

  LabelText =? stringFormat(:D}dt);//*

  LabelText =? stringFormat(:f}dt);//* :

  LabelText =? stringFormat(:F}dt);//* ::

  LabelText =? stringFormat(:g}dt);// :

  LabelText =? stringFormat(:G}dt);// ::

  LabelText =? stringFormat(:M}dt);//*

  LabelText =? stringFormat(:R}dt);//Sat Nov :: GMT

  LabelText =? stringFormat(:s}dt);//T::

  LabelText = stringFormat(:t}dt);//:

  LabelText = stringFormat(:T}dt);//::

  LabelText = stringFormat(:u}dt);// ::Z

  LabelText = stringFormat(:U}dt);//* ::

  LabelText = stringFormat(:Y}dt);//

  LabelText = stringFormat(dt);// ::?

  LabelText = stringFormat(:yyyyMMddHHmmssffff}dt); //yyyymm等可以設置比如LabelText = stringFormat(:yyyyMMdd}dt);

  綁定也適用:例:<%# stringFormat(:yyyyMMdd}eval_r(sj))%>


From:http://tw.wingwit.com/Article/program/net/201311/12583.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.