程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> C#當前日期得到本周的開始和結束日期

C#當前日期得到本周的開始和結束日期

編輯:關於C#
 

/// <summary>
/// 本周起止時間
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
private string weekrange(System.DateTime dt)
{
int weeknow = Convert.ToInt32(dt.DayOfWeek);
int daydiff = (-1) * weeknow;
int dayadd = 6-weeknow;
string datebegin = System.DateTime.Now.AddDays(daydiff).ToString("yyyyMMdd");
string dateend = System.DateTime.Now.AddDays(dayadd).ToString("yyyyMMdd");
return datebegin + " - " +dateend;
}

/// <summary>
/// 返回指定URL的源代碼
/// </summary>
/// <param name="url"></param>
private string GetHTML( string url,string tag)
{
byte[] buf = new byte[38192];
System.Net.WebRequest request = WebRequest.Create(url);;
WebResponse response =request.GetResponse();
Stream resStream = response.GetResponseStream();
int count = resStream.Read(buf, 0, buf.Length);
string result = Encoding.Default.GetString(buf, 0, count);
resStream.Close();
Regex reg=new Regex(@"(?<"+tag+">.*?</"+tag+">)",RegexOptions.IgnoreCase);
string output=reg.Match(result).Value;
return StripHTML(output);
}
/// <summary>
/// 去除HTML標記
/// </summary>
/// <param name="strHtml">包括HTML的源碼 </param>
/// <returns>已經去除後的文字</returns>
public static string StripHTML(string strHtml)
{
string [] aryReg ={
@"<script[^>]*?>.*?</script>",

@"<(///s*)?!?((/w+:)?/w+)(/w+(/s*=?/s*(([""'])(file://[""'tbnr]|[^/7])*?/7|/w+)|.{0})|/s)*?(///s*)?>",
@"([/r/n])[/s]+",
@"&(quot|#34);",
@"&(amp|#38);",
@"&(lt|#60);",
@"&(gt|#62);",
@"&(nbsp|#160);",
@"&(iexcl|#161);",
@"&(cent|#162);",
@"&(pound|#163);",
@"&(copy|#169);",
@"&#(/d+);",
@"-->",
@"<!--.*/n"

};

string [] aryRep = {
"",
"",
"",
"/"",
"&",
"<",
">",
" ",
"/xa1",//chr(161),
"/xa2",//chr(162),
"/xa3",//chr(163),
"/xa9",//chr(169),
"",
"/r/n",
""
};

string newReg =aryReg[0];
string strOutput=strHtml;
for(int i = 0;i<aryReg.Length;i++)
{
Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
strOutput = regex.Replace(strOutput,aryRep[i]);
}

strOutput.Replace("<","");
strOutput.Replace(">","");
strOutput.Replace("/r/n","");


return strOutput;
}
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved