| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Anaconda
- JQuery
- 말라키
- 가상환경
- Custom
- 파이썬
- Linux
- error
- ORA-28002
- Eclipse
- 리눅스
- 맥코트
- build
- STS
- HMI
- 명령어
- DataTables
- checkbox
- 원한
- pythoncom37.dll
- Python
- 분노
- geckodriver
- SCADA
- LOG
Archives
- Today
- Total
2010년 5월 1일, 2막
Convert TimeSpan to year, month, date (Age Calculation) in .NET 본문
출처 : http://techbrij.com/convert-timespan-to-year-month-date-age-calculation-in-net
private string 년월일구하기(DateTime t1,DateTime t2)
{
int 일 =t2.Day - t1.Day;
int 월 =t2.Month-t1.Month;
int 년 =t2.Year-t1.Year;
if (일<0)
{
일+=DateTime.DaysInMonth(t2.Year,t2.Month-1);
월--;
}
if(월<0)
{
월+=12;년--;
}
return 년.ToString()+"-"+월.ToString()+"-"+일.ToString() ;
}
public void TimeSpanToDate(DateTime d1, DateTime d2,out int years, out int months, out int days)
{
// compute & return the difference of two dates,
// returning years, months & days
// d1 should be the larger (newest) of the two dates
// we want d1 to be the larger (newest) date
// flip if we need to
if (d1 < d2)
{
DateTime d3= d2;
d2= d1;
d1= d3;
}
// compute difference in total months
months= 12 * (d1.Year - d2.Year) + (d1.Month - d2.Month);
// based upon the 'days',
// adjust months & compute actual days difference
if (d1.Day < d2.Day)
{
months--;
days = DateTime.DaysInMonth(d2.Year, d2.Month) - d2.Day + d1.Day;
}
else
{
days= d1.Day - d2.Day;
}
// compute years & actual months
years= months / 12;
months-= years * 12;
}
'Computer' 카테고리의 다른 글
| Run 32 bits fortinet SSL VPN in 64 bits Linux (0) | 2015.03.06 |
|---|---|
| [WORD] 머리글 및 바닥글에 장 번호와 제목 삽입 (0) | 2014.08.29 |
| [C#] datatable Join 방법 (0) | 2014.08.22 |
| RAW HDD 해결 방법 - TestDisk 사용법 (3) | 2014.05.23 |
| [SQL] mdb파일 switch 구문 (0) | 2014.04.04 |