Because the project requires a simple date help class, please forget it!
C #-code
// ================================================ ======================================
// Producnt name: boboarts. codemad
// Version 1.0
// Author: Dong Guangxiang
// Auto generated at: 2009-8-7 13:36:20
// ================================================ ======================================
Using system;
/// <Summary>
/// Date help class
/// </Summary>
Public static class Utility
{
// Day
Public static string nowtime ()
{
Return datetime. Now. year. tostring () + "-" + datetime. Now. Month. tostring () + "-" + datetime. Now. Day. tostring ();
}
// Subtract the corresponding days from the current day
Public static string gettimebydayreduce (double day)
{
Return datetime. now. year. tostring () + "-" + datetime. now. month. tostring () + "-" + datetime. now. adddays (day ). day. tostring ();
}
// Specify the first day of the month year
Public static datetime getfirstdayofmonth (INT year, int month)
{
Return convert. todatetime (Year. tostring () + "-" + month. tostring () + "-1 ");
}
// Specify the last day of the month year
Public static datetime getlastdayofmonth (INT year, int month)
{
Int days = datetime. daysinmonth (year, month );
Return convert. todatetime (Year. tostring () + "-" + month. tostring () + "-" + days. tostring ());
}
// The current week
Public static void thisweek (out string bdate, out string edate)
{
Datetime firstday = convert. todatetime (nowtime ());
Double theday;
If (firstday. dayofweek = dayofweek. Sunday) {theday = 7 ;}
Else if (firstday. dayofweek = dayofweek. Monday) {theday = 1 ;}
Else if (firstday. dayofweek = dayofweek. Tuesday) {theday = 2 ;}
Else if (firstday. dayofweek = dayofweek. Wednesday) {theday = 3 ;}
Else if (firstday. dayofweek = dayofweek. Thursday) {theday = 4 ;}
Else if (firstday. dayofweek = dayofweek. Friday) {theday = 5 ;}
Else {theday = 6 ;}
Double bday =-theday;
Double eday = 7-theday;
Bdate = firstday. adddays (bday). tostring ();
Edate = firstday. adddays (eday). tostring ();
}
// The past week
Public static void beforeweek (out string bdate, out string edate)
{
Datetime firstday = convert. todatetime (gettimebydayreduce (-thisweeklastday () + 1 ));
Double theday;
If (firstday. dayofweek = dayofweek. Sunday) {theday = 7 ;}
Else if (firstday. dayofweek = dayofweek. Monday) {theday = 1 ;}
Else if (firstday. dayofweek = dayofweek. Tuesday) {theday = 2 ;}
Else if (firstday. dayofweek = dayofweek. Wednesday) {theday = 3 ;}
Else if (firstday. dayofweek = dayofweek. Thursday) {theday = 4 ;}
Else if (firstday. dayofweek = dayofweek. Friday) {theday = 5 ;}
Else {theday = 6 ;}
Double bday =-theday;
Double eday = 7-theday;
Bdate = firstday. adddays (bday). tostring ();
Edate = firstday. adddays (eday). tostring ();
}
// Last day of the week
Public static double thisweeklastday ()
{
Datetime firstday = convert. todatetime (nowtime ());
Double theday;
If (firstday. dayofweek = dayofweek. Sunday) {theday = 7 ;}
Else if (firstday. dayofweek = dayofweek. Monday) {theday = 1 ;}
Else if (firstday. dayofweek = dayofweek. Tuesday) {theday = 2 ;}
Else if (firstday. dayofweek = dayofweek. Wednesday) {theday = 3 ;}
Else if (firstday. dayofweek = dayofweek. Thursday) {theday = 4 ;}
Else if (firstday. dayofweek = dayofweek. Friday) {theday = 5 ;}
Else {theday = 6 ;}
Return 7-theday;
}
// The first day of the month
Public static datetime getfirstdayofmonthtime ()
{
Return getfirstdayofmonth (datetime. Now. Year, datetime. Now. month );
}
// Last day of the month
Public static datetime getlastdayofmonthtime ()
{
Return getlastdayofmonth (datetime. Now. Year, datetime. Now. month );
}
// The first day of last month
Public static datetime getfirstdayofbeforemonthtime ()
{
Return getfirstdayofmonth (datetime. Now. Year, datetime. Now. Month-1 );
}
// Last day of last month
Public static datetime getlastdayofbeforemonthtime ()
{
Return getlastdayofmonth (datetime. Now. Year, datetime. Now. Month-1 );
}
// Obtain the corresponding time according to the drop-down box status
Public static void gettime (out string lastdatetime, out string firstdatetime, string state)
{
Switch (state)
{
Case "": firstdatetime = ""; lastdatetime = "";
Break;
Case "today": firstdatetime = nowtime (); lastdatetime = "";
Break;
Case "yesterday": firstdatetime = nowtime (); lastdatetime = gettimebydayreduce (-1 );
Break;
Case "last7days": firstdatetime = nowtime (); lastdatetime = gettimebydayreduce (-7 );
Break;
Case "thisweek": thisweek (Out firstdatetime, out lastdatetime );
Break;
Case "lastweek": beforeweek (Out firstdatetime, out lastdatetime );
Break;
Case "thismonth": firstdatetime = getfirstdayofmonthtime (). tostring (); lastdatetime = getlastdayofmonthtime (). tostring ();
Break;
Case "lastmonth": firstdatetime = getfirstdayofbeforemonthtime (). tostring (); lastdatetime = getlastdayofbeforemonthtime (). tostring ();
Break;
Default: firstdatetime = ""; lastdatetime = "";
Break;
}
}
}