asp.net常用的验证和获取日期的方法-创新互联

public string GetWeekOfFirstDay()
{
string ReasonTime;
switch (DateTime.Now.Date.DayOfWeek.ToString())
{
case "Monday":
ReasonTime=DateTime.Now.Date.ToString("yyyy-MM-dd");
return ReasonTime;
case "Tuesday":
ReasonTime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
return ReasonTime;
case "Wednesday":
ReasonTime = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd");
return ReasonTime;
case "Thursday":
ReasonTime = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd");
return ReasonTime;
case "Friday":
ReasonTime = DateTime.Now.AddDays(-4).ToString("yyyy-MM-dd");
return ReasonTime;
case "Saturday":
ReasonTime = DateTime.Now.AddDays(-5).ToString("yyyy-MM-dd");
return ReasonTime;
case "Sunday":
ReasonTime = DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd");
return ReasonTime;
default:
return DateTime.Now.Date.DayOfWeek.ToString("yyyy-MM-dd");
}
}// end GetWeekOfFirstDay()
public string TheFirstDayOfMonth()
{
int DayOfMonth = DateTime.Now.Day;
return DateTime.Now.AddDays(-DayOfMonth + 1).ToString("yyyy-MM-dd");
}
public string TheEndDayOfMonth()
{
int aMonthHaveDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
int DayOfMonth = DateTime.Now.Day;
int TheEndOfMonth = aMonthHaveDays - DayOfMonth;
return DateTime.Now.AddDays(TheEndOfMonth).ToString("yyyy-MM-dd");
}
public string TheFirstDayOfYear()
{//return2007-1-1
int dayOfYear = DateTime.Now.DayOfYear;
return DateTime.Now.AddDays(-dayOfYear + 1).ToString("yyyy-MM-dd");
}
public string TheEndDayOfYear()
{//return 2007-12-31
int month22HaveDays=DateTime.DaysInMonth(DateTime.Now.Year,12);
return DateTime.Now.Year + "-12-" + month22HaveDays;
}
public string GetDayAddWeekofDay(string strTime)
{//return 2007-3-3星期三
string Time = CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(Convert.ToDateTime(strTime)).ToString();
strTime = Convert.ToDateTime(strTime).ToString("yyyy-MM-dd");
switch (Time)
{
case "Monday":
strTime = strTime + "(星期一)";
return strTime;
case "Tuesday":
strTime = strTime + "(星期二)";
return strTime;
case "Wednesday":
strTime = strTime + "(星期三)";
return strTime;
case "Thursday":
strTime = strTime + "(星期四)";
return strTime;
case "Friday":
strTime = strTime + "(星期五)";
return strTime;
case "Saturday":
strTime = strTime + "(星期六)";
return strTime;
case "Sunday":
strTime = strTime + "(星期日)";
return strTime;
default:
return strTime;
}
}//end GetDayAddWeekofDay(string strTime)
public string GetFormatTime(string time)
{//return yyyy-MM-dd
if (time == "")
{
return "";
}
else
{
return Convert.ToDateTime(time).ToString("yyyy-MM-dd");
}
}
public string GetFormatMinutes(string time)
{
if (time == "")
{
return "";
}
else
{
return Convert.ToDateTime(time).ToString("yyyy-MM-dd HH:mm");
}
}
public bool RegexLongTime(string time)
{//yyyy-MM-dd hh:mm:ss
bool tureTime;
tureTime = System.Text.RegularExpressions.Regex.IsMatch(time, @"^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$");
return tureTime;
}
public bool RegexDate(string time)
{//yyyy-MM-dd
bool reasonTime;
string regex = @"^(19|20)\d\d[- /.](0[1-9]|1[012]|[1-9])[- /.](0[1-9]|[12][0-9]|3[01]|[1-9])$";
reasonTime = System.Text.RegularExpressions.Regex.IsMatch(time,regex);
return reasonTime;
}
public bool RegexInt32(string strInt)
{//int32
return System.Text.RegularExpressions.Regex.IsMatch(strInt, @"^\d+$");
}

成都创新互联从2013年成立,是专业互联网技术服务公司,拥有项目成都网站制作、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元天峻做网站,已为上家服务,为天峻各地企业和个人服务,联系电话:028-86922220

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:asp.net常用的验证和获取日期的方法-创新互联
本文地址:http://scjbc.cn/article/hdhos.html

其他资讯