Yahoo의 .NET 관련 라이브러리를 보던 중 괜찮은 메소드가 보여서 발췌했다.
.NET환경에서의 날자관련된 부분을 가지고 처리하다보면
Xnix 환경에서 작업하던 UnixTimestamp가 그리운게 사실이다.
다음 아래의 소스코드를 이용해서 자유롭게 Timestamp를 이용하면 되겠다.
/// <summary>
/// Returns the number of seconds since January 1st, 1970 for the current date and time.
/// </summary>
/// <returns>Number of seconds since January 1st, 1970.</returns>
public static long GetUnixTime()
{
return GetUnixTime(DateTime.UtcNow);
}/// <summary>
/// Returns the number of seconds since January 1st, 1970 from the given date and time.
/// </summary>
/// <param name="dateTimeUtc">Date and time to convert into Unix time in UTC.</param>
/// <returns>Number of seconds since January 1st, 1970 has elapsed since the given date and time.</returns>
public static long GetUnixTime(DateTime dateTimeUtc)
{
TimeSpan timestamp;// Get seconds since Jannuary 1, 1970 GMT
timestamp = dateTimeUtc - new DateTime(1970, 1, 1);return (long)Math.Floor(timestamp.TotalSeconds);
}
참조 주소 : http://developer.yahoo.com/dotnet/
'Development > .NET' 카테고리의 다른 글
| Microsoft Silverlight WPF/E를 한눈에 보여주는 동영상 (0) | 2007.06.02 |
|---|---|
| COM+ 자동등록 배치파일 (2) | 2007.05.30 |
| Gmail SMTP를 이용한 Mail 전송 ASP.NET 웹 프로그램 (2) | 2007.05.27 |
| 비쥬얼하게 이해하는 정렬(Sort) 알고리즘 (0) | 2007.05.26 |
| Windows Driver Foundation(WDF) (0) | 2007.05.26 |