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/