欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c# datetime方法應(yīng)用介紹

 更新時(shí)間:2012年11月21日 11:28:38   作者:  
本文將詳細(xì)介紹c# datetime方法應(yīng)用,需要了解更多的朋友可以參考下
隨著工作的需要,也算是寫一個(gè)為自己留著的幫助文檔吧。
System.DateTime currentTime=new System.DateTime(); //實(shí)例化一個(gè) datetime 對(duì)象
當(dāng)前 年月日時(shí)分秒 currentTime=System.DateTime.Now;
當(dāng)前 年 int 年=currentTime.Year;
當(dāng)前 月 int 月=currentTime.Month;
當(dāng)前 日 int 日=currentTime.Day;
當(dāng)前 時(shí) int 時(shí)=currentTime.Hour;
當(dāng)前 分 int 分=currentTime.Minute;
當(dāng)前 秒 int 秒=currentTime.Second;
當(dāng)前 毫秒 int 毫秒=currentTime.Millisecond; (變量可用中文)
DateTime.Now.ToString();//獲取當(dāng)前系統(tǒng)時(shí)間 完整的日期和時(shí)間
DateTime.Now.ToLongDateString();//只顯示日期 xxxx年xx月xx日 ,一個(gè)是長日期
DateTime.Now.ToShortDateString();//只顯示日期 xxxx-xx-xx 一個(gè)是短日期
DateTime.Now.Date.ToShortDateString();//今天
DateTime.Now.AddDays(-1).ToShortDateString();//昨天
DateTime.Now.AddDays(1).ToShortDateString();//明天 
中文日期 年月日時(shí)分 string strY=currentTime.ToString("f"); //不顯示秒
中文日期 年月 string strYM=currentTime.ToString("y");
中文日期 月日 string strMD=currentTime.ToString("m");
當(dāng)前 年月日 格式為:2003-9-23 string strYMD=currentTime.ToString("d");
當(dāng)前 時(shí)分 格式為:14:24 string strT=currentTime.ToString("t");
更多格式看 附1、2。 

//本周 (注意這里的每一周是從周日始至周六止)
DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
//上周 (上周就是本周再減去7天)
DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek))) - 7).ToShortDateString();
DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek))) - 7).ToShortDateString();
//下周 (本周再加上7天)
DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek))) + 7).ToShortDateString();
DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek))) + 7).ToShortDateString();
//本月 (本月的第一天是1號(hào),最后一天就是下個(gè)月一號(hào)再減一天)
DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "1"; //第一天
DateTime.Parse(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "1").AddMonths(1).AddDays(-1).ToShortDateString();//最后一天
--------------------------------------------------------------------------------
附1:datetime類型在tostring(),format的格式設(shè)置
格式字符  關(guān)聯(lián)屬性/說明
d   ShortDatePattern
LongDatePattern 
完整日期和時(shí)間(長日期和短時(shí)間)
FullDateTimePattern(長日期和長時(shí)間)
g   常規(guī)(短日期和短時(shí)間)
G   常規(guī)(短日期和長時(shí)間)
m、M   MonthDayPattern
r、R   RFC1123Pattern
使用當(dāng)?shù)貢r(shí)間的 SortableDateTimePattern(基于 ISO 8601)
t   ShortTimePattern
T   LongTimePattern
u  UniversalSortableDateTimePattern 用于顯示通用時(shí)間的格式
使用通用時(shí)間的完整日期和時(shí)間(長日期和長時(shí)間)
y、Y  y、Y YearMonthPattern

附2:下表列出了可被合并以構(gòu)造自定義模式的模式。這些模式是區(qū)分大小寫的
格式字符 關(guān)聯(lián)屬性/說明
月中的某一天。一位數(shù)的日期沒有前導(dǎo)零。
dd   月中的某一天。一位數(shù)的日期有一個(gè)前導(dǎo)零。
ddd   周中某天的縮寫名稱,在 AbbreviatedDayNames 中定義。
dddd  周中某天的完整名稱,在 DayNames 中定義。
M   月份數(shù)字。一位數(shù)的月份沒有前導(dǎo)零。
MM   月份數(shù)字。一位數(shù)的月份有一個(gè)前導(dǎo)零。
MMM  月份的縮寫名稱,在 AbbreviatedMonthNames 中定義。
MMMM  月份的完整名稱,在 MonthNames 中定義。
y   不包含紀(jì)元的年份。如果不包含紀(jì)元的年份小于 10,則顯示不具有前導(dǎo)零的年份。
yy  不包含紀(jì)元的年份。如果不包含紀(jì)元的年份小于 10,則顯示具有前導(dǎo)零的年份。
yyyy  包括紀(jì)元的四位數(shù)的年份。
gg  時(shí)期或紀(jì)元。如果要設(shè)置格式的日期不具有關(guān)聯(lián)的時(shí)期或紀(jì)元字符串,則忽略該模式。
h   12小時(shí)制的小時(shí)。一位數(shù)的小時(shí)數(shù)沒有前導(dǎo)零。
hh   12 小時(shí)制的小時(shí)。一位數(shù)的小時(shí)數(shù)有前導(dǎo)零。
H 24 小時(shí)制的小時(shí)。一位數(shù)的小時(shí)數(shù)沒有前導(dǎo)零。 
HH  24 小時(shí)制的小時(shí)。一位數(shù)的小時(shí)數(shù)有前導(dǎo)零。

相關(guān)文章

最新評(píng)論