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+$");
}

我们提供的服务有:成都网站建设、网站设计、微信公众号开发、网站优化、网站认证、昌江ssl等。为千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的昌江网站制作公司


网站题目:asp.net常用的验证和获取日期的方法
文章地址:http://bzwzjz.com/article/isphge.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站建设费用 企业手机网站建设 公司网站建设 响应式网站设计 成都网站建设 定制级高端网站建设 成都网站制作 网站建设开发 网站设计 企业网站设计 成都定制网站建设 响应式网站建设 成都网站建设 重庆外贸网站建设 营销型网站建设 成都网站建设公司 响应式网站设计方案 成都企业网站设计 高端网站设计 成都响应式网站建设 教育网站设计方案 网站设计公司