问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

asp.net中dropdownlist绑定日期时间,函数处理值

发布网友 发布时间:2022-04-27 15:35

我来回答

3个回答

懂视网 时间:2022-04-27 19:57

代码如下:

using System;
namespace Utilities
{
/// <summary>
/// Common DateTime Methods.
/// </summary>
///
public enum Quarter
{
First = 1,
Second = 2,
Third = 3,
Fourth = 4
}
public enum Month
{
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12
}
public class DateUtilities
{
#region Quarter
public static DateTime GetStartOfQuarter( int Year, Quarter Qtr )
{
if( Qtr == Quarter.First ) // 1st Quarter = January 1 to March 31
return new DateTime( Year, 1, 1, 0, 0, 0, 0 );
else if( Qtr == Quarter.Second ) // 2nd Quarter = April 1 to June 30
return new DateTime( Year, 4, 1, 0, 0, 0, 0 );
else if( Qtr == Quarter.Third ) // 3rd Quarter = July 1 to September 30
return new DateTime( Year, 7, 1, 0, 0, 0, 0 );
else // 4th Quarter = October 1 to December 31
return new DateTime( Year, 10, 1, 0, 0, 0, 0 );
}
public static DateTime GetEndOfQuarter( int Year, Quarter Qtr )
{
if( Qtr == Quarter.First ) // 1st Quarter = January 1 to March 31
return new DateTime( Year, 3, DateTime.DaysInMonth( Year, 3 ), 23, 59, 59, 999 );
else if( Qtr == Quarter.Second ) // 2nd Quarter = April 1 to June 30
return new DateTime( Year, 6, DateTime.DaysInMonth( Year, 6 ), 23, 59, 59, 999 );
else if( Qtr == Quarter.Third ) // 3rd Quarter = July 1 to September 30
return new DateTime( Year, 9, DateTime.DaysInMonth( Year, 9 ), 23, 59, 59, 999 );
else // 4th Quarter = October 1 to December 31
return new DateTime( Year, 12, DateTime.DaysInMonth( Year, 12 ), 23, 59, 59, 999 );
}
public static Quarter GetQuarter( Month month )
{
if( month <= Month.March ) // 1st Quarter = January 1 to March 31
return Quarter.First;
else if( ( month >= Month.April ) && ( month <= Month.June ) ) // 2nd Quarter = April 1 to June 30
return Quarter.Second;
else if( ( month >= Month.July ) && ( month <= Month.September ) ) // 3rd Quarter = July 1 to September 30
return Quarter.Third;
else // 4th Quarter = October 1 to December 31
return Quarter.Fourth;
}
public static DateTime GetEndOfLastQuarter()
{
if( DateTime.Now.Month <= (int)Month.March ) //go to last quarter of previous year
return GetEndOfQuarter( DateTime.Now.Year - 1, GetQuarter( Month.December ));
else //return last quarter of current year
return GetEndOfQuarter( DateTime.Now.Year, GetQuarter( (Month)DateTime.Now.Month));
}
public static DateTime GetStartOfLastQuarter()
{
if( DateTime.Now.Month <= 3 ) //go to last quarter of previous year
return GetStartOfQuarter( DateTime.Now.Year - 1, GetQuarter( Month.December ));
else //return last quarter of current year
return GetStartOfQuarter( DateTime.Now.Year, GetQuarter( (Month)DateTime.Now.Month));
}
public static DateTime GetStartOfCurrentQuarter()
{
return GetStartOfQuarter( DateTime.Now.Year, GetQuarter( (Month)DateTime.Now.Month ));
}
public static DateTime GetEndOfCurrentQuarter()
{
return GetEndOfQuarter( DateTime.Now.Year, GetQuarter( (Month)DateTime.Now.Month ));
}
#endregion
#region Weeks
public static DateTime GetStartOfLastWeek()
{
int DaysToSubtract = (int)DateTime.Now.DayOfWeek + 7;
DateTime dt = DateTime.Now.Subtract( System.TimeSpan.FromDays( DaysToSubtract ) );
return new DateTime( dt.Year, dt.Month, dt.Day, 0, 0, 0, 0 );
}
public static DateTime GetEndOfLastWeek()
{
DateTime dt = GetStartOfLastWeek().AddDays(6);
return new DateTime( dt.Year, dt.Month, dt.Day, 23, 59, 59, 999 );
}
public static DateTime GetStartOfCurrentWeek()
{
int DaysToSubtract = (int)DateTime.Now.DayOfWeek ;
DateTime dt = DateTime.Now.Subtract( System.TimeSpan.FromDays( DaysToSubtract ) );
return new DateTime( dt.Year, dt.Month, dt.Day, 0, 0, 0, 0 );
}
public static DateTime GetEndOfCurrentWeek()
{
DateTime dt = GetStartOfCurrentWeek().AddDays(6);
return new DateTime( dt.Year, dt.Month, dt.Day, 23, 59, 59, 999 );
}
#endregion
#region Months
public static DateTime GetStartOfMonth( int Month, int Year )
{
return new DateTime( Year, Month, 1, 0, 0, 0, 0 );
}
public static DateTime GetEndOfMonth( int Month, int Year )
{
return new DateTime( Year, Month, DateTime.DaysInMonth( Year, Month ), 23, 59, 59, 999 );
}
public static DateTime GetStartOfLastMonth()
{
if( DateTime.Now.Month == 1 )
return GetStartOfMonth( 12, DateTime.Now.Year - 1);
else
return GetStartOfMonth( DateTime.Now.Month -1, DateTime.Now.Year );
}
public static DateTime GetEndOfLastMonth()
{
if( DateTime.Now.Month == 1 )
return GetEndOfMonth( 12, DateTime.Now.Year - 1);
else
return GetEndOfMonth( DateTime.Now.Month -1, DateTime.Now.Year );
}
public static DateTime GetStartOfCurrentMonth()
{
return GetStartOfMonth( DateTime.Now.Month, DateTime.Now.Year );
}
public static DateTime GetEndOfCurrentMonth()
{
return GetEndOfMonth( DateTime.Now.Month, DateTime.Now.Year );
}
#endregion
#region Years
public static DateTime GetStartOfYear( int Year )
{
return new DateTime( Year, 1, 1, 0, 0, 0, 0 );
}
public static DateTime GetEndOfYear( int Year )
{
return new DateTime( Year, 12, DateTime.DaysInMonth( Year, 12 ), 23, 59, 59, 999 );
}
public static DateTime GetStartOfLastYear()
{
return GetStartOfYear( DateTime.Now.Year - 1 );
}
public static DateTime GetEndOfLastYear()
{
return GetEndOfYear( DateTime.Now.Year - 1 );
}
public static DateTime GetStartOfCurrentYear()
{
return GetStartOfYear( DateTime.Now.Year );
}
public static DateTime GetEndOfCurrentYear()
{
return GetEndOfYear( DateTime.Now.Year );
}
#endregion
#region Days
public static DateTime GetStartOfDay( DateTime date )
{
return new DateTime( date.Year, date.Month, date.Day, 0, 0, 0, 0 );
}
public static DateTime GetEndOfDay( DateTime date )
{
return new DateTime( date.Year, date.Month, date.Day, 23, 59, 59, 999 );
}
#endregion
}
}

热心网友 时间:2022-04-27 17:05

2个方法
先把绑定的值 用string loginTime变量取出来,

loginTime =( Convert.ToDateTime(loginTime)).Year.ToString();
这个方法取出来。
2.loginTime.Substring(0,4);这个方法也行

热心网友 时间:2022-04-27 18:23

string.Format("{0:yyyy-MM-dd}",logintime)
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
ef英语哪个好 EF英孚英语培训怎么样? 英孚英语好不好 EF英孚教育到底好不好 大佬们,麦芒7和荣耀10那个值得入手?2500以下的机子还有啥好推荐的么... 介绍几款2500元以前的手机 像素一定要高 其他的不做要求 近期想入手一部安卓手机,价格2200到2500左右…买HTC desire Z还是 三星... 笔记本忘记开机密码怎么办急死了 笔记本电脑屏幕开机锁忘记密码 怎么办?急死了 华硕笔记本电脑开机密码忘记了怎样找回?系统是Windows 7旗舰版... 假设使用交通银行信用卡消费5000元,分6期还,每期还多少?总还金额?顺求公式? 平安信用卡消费5000分6期每期要还多少?利息是多少? 求搞笑不虐轻松的穿越文,皇帝专宠皇后的那一种 一本超宠的宫廷文,男主是皇上,女主是一个妃子,后来好像当了皇后。女主和太后关系很好,有两次和男主吵 穿越架空小说,女主是皇后,男主是皇上,很宠女主。轻松一点儿的。完结一对一。魂穿哦。 古代穿越小说,成为皇上的宠妃皇后 关于皇帝宠皇后的言情小说短篇 关于皇上宠爱皇后,和皇后相爱的小说,清朝穿越的小说。最好从小时候写起。 关于皇帝和皇后的小说 皇帝重生,养成小皇后的小说,不是“小小宠后初养成” 有什么关于女主角是皇后,男主角是皇上的言情小说,最好虐一点的 有什么好看的穿越小说,要女主角是皇后,然后皇上对她很宠爱,不要一女N男,不要VIP章节! 求一本看过的小说名,女主怕麻烦,男主是皇上,很宠爱女主并且千方百计想让女主当皇后的宠文 有没有刚入宫时位分低然后皇上宠爱一步一步晋升,最后成了皇后的小说? 求古代言情小说,要皇上和皇后的,最好皇上是霸道且宠皇后的那种。谢谢。 古代言情皇上专宠皇后好看的小说 力魔发动机清洗剂2427加入后跑10分钟在放出行吗 力魔 三元催化清洁剂 8931怎么样 得了尘肺怎么治疗最好 尘肺病请问要怎么治疗 联想Y7000 BIOS怎么关闭ACPI C#&#47;asp.net 中怎么取得在类库中嵌入资源的最后修改时间?并转成时间戳 显卡已经升级gtx1060-6G了 我这个配置为什么吃鸡fps最高才一百多一点点 而且经常都是50 1060吃鸡才50fps是为什么 求个现在版本吃鸡1060最高帧数的显卡驱动版本~ i7–6700 1060 6G显卡 16G内存 求大神教我配置吃鸡设置 ,保证在60fps 1060加3470我这个配置如果再提升吃鸡帧数流畅度的话需要换什么 现在绝地求生版本用1060 3g显卡最多fps好多啊? 这配置换个1060的显卡 加根内存 玩吃鸡卡不卡 能有多少fps? 直播绿通是什么意思 新北京中心是北京市绿通项目之一,绿通项目是什么意思? PHP使用面向过程方式接收do while循环输出数据 php这段代码怎么写,面向过程会,刚接触面向对象,还不太懂 php写个面向过程的脚本,只需要查查API就可以了,真的有这么简单吗 谁能帮我写一篇西安城市夜景散文? 给一篇描写西安的英文文章 谁能给我弄一篇介绍西安悠久历史的文章,要超过两千字 西安家乡的景物作文 贾平凹的《西安这座城》 asp.net 中常用的 类库有哪些?