2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

C#中獲取當前時間方法

 TUSHUGUANMM 2011-01-10

--DateTime 數(shù)字型
System.DateTime currentTime=new System.DateTime();
取當前年月日時分秒      currentTime=System.DateTime.Now;
取當前年     int 年=currentTime.Year;
取當前月     int 月=currentTime.Month;
取當前日     int 日=currentTime.Day;
取當前時     int 時=currentTime.Hour;
取當前分     int 分=currentTime.Minute;
取當前秒     int 秒=currentTime.Second;
取當前毫秒    int 毫秒=currentTime.Millisecond; (變量可用中文)

取中文日期顯示——年月日時分    string strY=currentTime.ToString("f"); //不顯示秒

取中文日期顯示_年月       string strYM=currentTime.ToString("y");

取中文日期顯示_月日     string strMD=currentTime.ToString("m");

取當前年月日,格式為:2003-9-23      string strYMD=currentTime.ToString("d");

取當前時分,格式為:14:24      string strT=currentTime.ToString("t");

DateTime.Now.ToString();//獲取當前系統(tǒng)時間完整的日期和時間
DateTime.Now.ToLongDateString();//
只顯示日期 xxxx年xx月xx日,一個是長日期
DateTime.Now.ToShortDateString();//只顯示日期 xxxx-xx-xx 一個是短日期

//今天        DateTime.Now.Date.ToShortDateString();
//昨天的       DateTime.Now.AddDays(-1).ToShortDateString();
//明天的       DateTime.Now.AddDays(1).ToShortDateString();


//本周(注意這里的每一周是從周日始至周六止)
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號,最后一天就是下個月一號再減一天。

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();//最后一天

另一種方法:

DateTime now = DateTime.Now;
DateTime d1 = new DateTime(now.Year, now.Month, 1); //本月第一天

DateTime d2 = d1.AddMonths(1).AddDays(-1); //本月最后一天

PS:

 

DateTime.Now.DayOfWeek.ToString();//英文星期顯示,Wednesday

(int)DateTime.Now.DayOfWeek     數(shù)字,若是周三,結果對應為3

DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-cn")); //中文星期顯示
DateTime.Now.ToString("dddd");//中文星期顯示

DateTime.Now.ToString("dddd,MMMM,dd ,yyyy", new System.Globalization.DateTimeFormatInfo());//顯示日期格式Friday,July, 01,2009

DateTime.Now.ToString("dddd,dd MMMM,yyyy") //輸出   星期三,30 一月,2008


    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多