- 爱易网页
-
ASP.NET教程
- 通過datatime.now()得到相應的開始日期和結束日期。该如何处理
日期:2014-05-18 浏览次数:20474 次
通過datatime.now()得到相應的開始日期和結束日期。
starttime:textbox endtime:textbox
Page_load()
1.得到该周一時間和该周末的時間;
2.得到该月开始時間和该月结束時間;
3.得到该季度开始時間和该季度结束時間;
4.得到该年度开始時間和该年度结束時間;
如何用C#实现.或Javascript实现。
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Globalization;
namespace Digdotnet
{
/// <summary>
/// 表示公历历法帮助类。
/// </summary>
public static class CalendarHelper
{
public const int DaysOfFullLeapYear = 366;
public const int DaysOfFullInleapYear = 365;
public const int DaysOfSecondHalfYear = 184;
public const int DaysInWeek = 7;
private readonly static DateTime InternalMinDate = new DateTime(1900, 1, 1);
private readonly static Calendar InternalCalendar = Calendar.ReadOnly(new GregorianCalendar());
//DateTime now = DateTime.Now;
#region
public static HalfYearKind GetHalfYearOfYear(DateTime time)
{
return GetHalfYearOfYear(time.Month);
}
public static HalfYearKind GetHalfYearOfYear(QuarterKind quarter)
{
if (quarter == QuarterKind.First || quarter == QuarterKind.Second) {
return HalfYearKind.FirstHalf;
}
else {
return HalfYearKind.SecondHalf;
}
}
public static HalfYearKind GetHalfYearOfYear(int month)
{
if (month < 1 || month > 12) {
throw new ArgumentOutOfRangeException( "month ", month, "参数必须大于0且小于13。 ");
}
return (HalfYearKind)(month / 7 + 1);
}
public static QuarterKind GetQuarterOfYear(DateTime time)
{
return GetQuarterOfYear((byte)time.Month);
}
public static QuarterKind GetQuarterOfYear(int month)
{
if (month < 1 || month > 12) {
throw new ArgumentOutOfRangeException( "month ", month, "参数必须大于0且小于13。 ");
}
if (month > 7) {
month += 2;
}
return (QuarterKind)(month / 4 + 1);
}
public static TendaysKind GetTendaysOfMonth(DateTime time)
{
return GetTendaysOfMonth((byte)time.Day);
}
public static TendaysKind GetTendaysOfMonth(int dayOfMonth)
{
if (dayOfMonth < 1 || dayOfMonth > 31) {
throw new ArgumentOutOfRangeException( "dayOfMonth ", dayOfMonth, "参数必须大于0且小于32。 ");
}
if (dayOfMonth > 20) {
dayOfMonth++;
}
return (TendaysKind)(dayOfMonth / 11 + 1);
}
/// <summary>
/// 返回指定半年间的第一个月。
/// </summary>
/// <param name= "value "> </param>
/// <returns> </returns>
public static int GetFirstMonthOfHalfYear(HalfYearKind value)
{
return (value == HalfYearKind.FirstHalf) ? 1 : 7;
}