using system;
namespace ehr.common
#region 方法
/// 返回本年有多少天
/// 年份
/// 本年的天數
public static int getdaysofyear(int iyear)
else
return cnt; }
/// 本年有多少天
/// 日期
/// 本天在當年的天數
public static int getdaysofyear(datetime idt)
else
} /// 本月有多少天
/// 年
/// 月
/// 天數
public static int getdaysofmonth(int iyear,int month)
else
break;
case 3:
days = 31;
break;
case 4:
days = 30;
break;
case 5:
days = 31;
break;
case 6:
days = 30;
break;
case 7:
days = 31;
break;
case 8:
days = 31;
break;
case 9:
days = 30;
break;
case 10:
days = 31;
break;
case 11:
days = 30;
break;
case 12:
days = 31;
break;
}
return days ; }
/// 本月有多少天
/// 日期
/// 天數
public static int getdaysofmonth(datetime dt)
else
break;
case 3:
days = 31;
break;
case 4:
days = 30;
break;
case 5:
days = 31;
break;
case 6:
days = 30;
break;
case 7:
days = 31;
break;
case 8:
days = 31;
break;
case 9:
days = 30;
break;
case 10:
days = 31;
break;
case 11:
days = 30;
break;
case 12:
days = 31;
break;
}
return days ; }
/// 返回當前日期的星期名稱
/// 日期
/// 星期名稱
public static string getweeknameofday(datetime idt)
return week; }
/// 返回當前日期的星期編號
/// 日期
/// 星期數字編號
public static string getweeknumberofday(datetime idt)
return week; }
/// 判斷當前日期所屬的年份是否是閏年,私有函式
/// 日期
/// 是閏年:true ,不是閏年:false
private static bool isruyear(datetime idt)
else
} /// 判斷當前年份是否是閏年,私有函式
/// 年份
/// 是閏年:true ,不是閏年:false
private static bool isruyear(int iyear)
else
} ///
/// 將輸入的字串轉化為日期。如果字串的格式非法,則返回當前日期。
///
/// 輸入字串
/// 日期物件
public static datetime convertstringtodate(string strinput)
catch(exception)
return odatetime; }
///
/// 將日期物件轉化為格式字串
///
/// 日期物件
///
/// 格式:
/// "shortdate"===短日期
/// "longdate"==長日期
/// 其它====自定義格式
///
/// 日期字串
public static string convertdatetostring(datetime odatetime,string strformat)
} catch(exception)
return strdate; }
///
/// 判斷是否為合法日期,必須大於2023年1月1日
///
/// 輸入日期字串
/// true/false
public static bool isdatetime(string strdate)
catch(exception)
} ///
/// 獲取兩個日期之間的差值,獲取年數使用 (int)datediff(string howtocompare, datetime startdate, datetime enddate)
///
/// 比較的方式:year month day hour minute second
/// 開始日期
/// 結束日期
/// 時間差
public static double datediff(string howtocompare, datetime startdate, datetime enddate)
} catch(exception)
return diff; }
#endregion }
}
日期處理工具類
public class dateutils 日期格式化 日期格式為 yyyy mm dd param date 日期 param pattern 格式,如 dateutils.date time pattern return 返回yyyy mm dd格式日期 public static strin...
C 日期處理函式
1 datetime 數字型 system.datetime currenttime new system.datetime 1.1 取當前年月日時分秒 currenttime system.datetime.now 1.2 取當前年 int 年 currenttime.year 1.3 取當前月 ...
C 日期處理函式
posted on 2006 10 22 21 07 劍氣瀟瀟 閱讀 729 編輯收藏 1 datetime 數字型 system.datetime currenttime new system.datetime 1.1 取當前年月日時分秒 currenttime system.datetime.n...