심재운 블로그


namespace DateTimeLibrary
{
    using System;
    using System.Collections;

    public class DateTimeLibrary
    {
        public static string FirstDayOfCurrentMonth()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month, 1);
            return time2.ToShortDateString();
        }

        public static string FirstDayOfCurrenttQuarter()
        {
            DateTime time2;
            DateTime time3;
            DateTime today = DateTime.Today;
            int num = int.Parse(today.Month.ToString());
            if (num != 0)
            {
                int num2 = (num % 3) - 1;
                time3 = today.AddMonths(-num2);
                time2 = new DateTime(time3.Year, time3.Month, 1);
            }
            else
            {
                time3 = today.AddMonths(-2);
                time2 = new DateTime(time3.Year, time3.Month, 1);
            }
            return time2.ToShortDateString();
        }

        public static string FirstDayOfCurrenttWeek()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month, today.Day);
            Hashtable hashtable = new Hashtable();
            hashtable["Monday"] = "0";
            hashtable["Tuesday"] = "1";
            hashtable["Wednesday"] = "2";
            hashtable["Thursday"] = "3";
            hashtable["Friday"] = "4";
            hashtable["Saturday"] = "5";
            hashtable["Sunday"] = "6";
            string s = (string) hashtable[today.DayOfWeek.ToString()];
            int num = int.Parse(s);
            return time2.AddDays((double) -num).ToShortDateString();
        }

        public static string FirstDayOfCurrentYear()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, 1, 1);
            return time2.ToShortDateString();
        }

        public static string FirstDayOfLastMonth()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month - 1, 1);
            return time2.ToShortDateString();
        }

        public static string FirstDayOfLastQuarter()
        {
            DateTime time2;
            DateTime time3;
            DateTime today = DateTime.Today;
            int num = int.Parse(today.Month.ToString());
            if (num != 0)
            {
                int num2 = (num % 3) - 1;
                time3 = today.AddMonths(-(num2 + 3));
                time2 = new DateTime(time3.Year, time3.Month, 1);
            }
            else
            {
                time3 = today.AddMonths(-5);
                time2 = new DateTime(time3.Year, time3.Month, 1);
            }
            return time2.ToShortDateString();
        }

        public static string FirstDayOfLastWeek()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month, today.Day);
            Hashtable hashtable = new Hashtable();
            hashtable["Monday"] = "0";
            hashtable["Tuesday"] = "1";
            hashtable["Wednesday"] = "2";
            hashtable["Thursday"] = "3";
            hashtable["Friday"] = "4";
            hashtable["Saturday"] = "5";
            hashtable["Sunday"] = "6";
            string s = (string) hashtable[today.DayOfWeek.ToString()];
            int num = int.Parse(s) + 7;
            return time2.AddDays((double) -num).ToShortDateString();
        }

        public static string FirstDayOfLastYear()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year - 1, 1, 1);
            return time2.ToShortDateString();
        }

        public static string FirstDayOfNextMonth()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month + 1, 1);
            return time2.ToShortDateString();
        }

        public static string FirstDayOfNextQuarter()
        {
            DateTime time3;
            DateTime today = DateTime.Today;
            int num = int.Parse(today.Month.ToString());
            if (num != 0)
            {
                int month = num + (3 - (num % 3));
                DateTime time2 = new DateTime(today.Year, month, 1);
                time3 = time2.AddMonths(1);
            }
            else
            {
                time3 = new DateTime(today.Year, today.Month, 1).AddMonths(1);
            }
            return time3.ToShortDateString();
        }

        public static string FirstDayOfNextWeek()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month, today.Day);
            Hashtable hashtable = new Hashtable();
            hashtable["Monday"] = "0";
            hashtable["Tuesday"] = "1";
            hashtable["Wednesday"] = "2";
            hashtable["Thursday"] = "3";
            hashtable["Friday"] = "4";
            hashtable["Saturday"] = "5";
            hashtable["Sunday"] = "6";
            string s = (string) hashtable[today.DayOfWeek.ToString()];
            int num = int.Parse(s);
            return time2.AddDays((double) (-num + 7)).ToShortDateString();
        }

        public static string FirstDayOfNextYear()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year + 1, 1, 1);
            return time2.ToShortDateString();
        }

        public static string LastDayOfCurrentMonth()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month + 1, 1);
            return time2.AddDays(-1.0).ToShortDateString();
        }

        public static string LastDayOfCurrenttQuarter()
        {
            DateTime time2;
            DateTime time3;
            DateTime today = DateTime.Today;
            int num = int.Parse(today.Month.ToString());
            if (num != 0)
            {
                int month = num + (3 - (num % 3));
                time2 = new DateTime(today.Year, month, 1);
                time2.AddMonths(1);
                time2.AddDays(-1.0);
                time3 = time2.AddMonths(1).AddDays(-1.0);
            }
            else
            {
                time2 = new DateTime(today.Year, today.Month, 1);
                time2.AddMonths(1);
                time2.AddDays(-1.0);
                time3 = time2.AddMonths(1).AddDays(-1.0);
            }
            return time3.ToShortDateString();
        }

        public static string LastDayOfCurrentWeek()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month, today.Day);
            Hashtable hashtable = new Hashtable();
            hashtable["Monday"] = "0";
            hashtable["Tuesday"] = "1";
            hashtable["Wednesday"] = "2";
            hashtable["Thursday"] = "3";
            hashtable["Friday"] = "4";
            hashtable["Saturday"] = "5";
            hashtable["Sunday"] = "6";
            string s = (string) hashtable[today.DayOfWeek.ToString()];
            int num = int.Parse(s) + 1;
            return time2.AddDays((double) (-num + 7)).ToShortDateString();
        }

        public static string LastDayOfCurrentYear()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, 12, 0x1f);
            return time2.ToShortDateString();
        }

        public static string LastDayOfLastMonth()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month - 1, 1);
            return time2.AddMonths(1).AddDays(-1.0).ToShortDateString();
        }

        public static string LastDayOfLastQuarter()
        {
            DateTime time2;
            DateTime time3;
            DateTime today = DateTime.Today;
            int num = int.Parse(today.Month.ToString());
            if (num != 0)
            {
                int month = num + (3 - (num % 3));
                time2 = new DateTime(today.Year, month, 1);
                time3 = time2.AddMonths(1).AddDays(-1.0).AddMonths(-3);
            }
            else
            {
                time2 = new DateTime(today.Year, today.Month, 1);
                time3 = time2.AddMonths(1).AddDays(-1.0).AddMonths(-3);
            }
            return time3.ToShortDateString();
        }

        public static string LastDayOfLastYear()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year - 1, 12, 0x1f);
            return time2.ToShortDateString();
        }

        public static string LastDayOfNextMonth()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month + 2, 1);
            return time2.AddDays(-1.0).ToShortDateString();
        }

        public static string LastDayOfNextQuarter()
        {
            DateTime time2;
            DateTime time3;
            DateTime today = DateTime.Today;
            int num = int.Parse(today.Month.ToString());
            if (num != 0)
            {
                int month = num + (3 - (num % 3));
                time2 = new DateTime(today.Year, month, 1);
                time3 = time2.AddMonths(1).AddMonths(3).AddDays(-1.0);
            }
            else
            {
                time2 = new DateTime(today.Year, today.Month, 1);
                time3 = time2.AddMonths(1).AddMonths(3).AddDays(-1.0);
            }
            return time3.ToShortDateString();
        }

        public static string LastDayOfNextWeek()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month, today.Day);
            Hashtable hashtable = new Hashtable();
            hashtable["Monday"] = "0";
            hashtable["Tuesday"] = "1";
            hashtable["Wednesday"] = "2";
            hashtable["Thursday"] = "3";
            hashtable["Friday"] = "4";
            hashtable["Saturday"] = "5";
            hashtable["Sunday"] = "6";
            string s = (string) hashtable[today.DayOfWeek.ToString()];
            int num = int.Parse(s) + 1;
            return time2.AddDays((double) (-num + 14)).ToShortDateString();
        }

        public static string LastDayOfNextYear()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year + 1, 12, 0x1f);
            return time2.ToShortDateString();
        }

        public static string LastOfLastWeek()
        {
            DateTime today = DateTime.Today;
            DateTime time2 = new DateTime(today.Year, today.Month, today.Day);
            Hashtable hashtable = new Hashtable();
            hashtable["Monday"] = "0";
            hashtable["Tuesday"] = "1";
            hashtable["Wednesday"] = "2";
            hashtable["Thursday"] = "3";
            hashtable["Friday"] = "4";
            hashtable["Saturday"] = "5";
            hashtable["Sunday"] = "6";
            string s = (string) hashtable[today.DayOfWeek.ToString()];
            int num = int.Parse(s) + 1;
            return time2.AddDays((double) -num).ToShortDateString();
        }
    }
}




이 글을 공유합시다

facebook twitter kakaoTalk kakaostory naver band

본문과 관련 있는 내용으로 댓글을 남겨주시면 감사하겠습니다.

비밀글모드