| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
- Ajax
- 자바스크립트
- 실버라이트
- 구글
- 개발자
- C#
- jQuery
- COM+
- 게으름
- XML
- WEb 2.0 Expo
- GDI+
- 형태소분석기
- 암호화
- MS
- 실버라이트2
- Web 2.0
- ASP.NET
- GTD
- 성공
- silverlight
- 해킹
- hnd-7070
- 검색
- .net
- 전기차
- Sliverlight
- 리팩토링
- 백신
- JavaScript
- Today
- Total
꿈으로 가는 작은 계단
DateTime형 유용한 유틸리티 본문
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();
}
}
}
'소프트웨어 > C# & ASP.NET' 카테고리의 다른 글
| ASP.NET 2.0에서 중첩 Repeater 사용하기 (0) | 2009.11.03 |
|---|---|
| C# 초보자분들을 위한 기초강좌 (0) | 2009.11.03 |
| Java vs. .NET 성능 비교 (0) | 2009.10.09 |
| XML 파일 읽기를 테스트해 보았다... (Count) (0) | 2009.09.29 |
| Visual Studio 2010 CTP 버전 다운로드 주소 (0) | 2009.08.27 |