728x90
반응형
728x170
▶ Assembly 클래스 : 어셈블리 빌드 날짜 구하기 예제
using System;
using System.Reflection;
Assembly assembly = Assembly.LoadFrom(@"D:\ARCA.HOME\ARCA.BINARY.RELEASE\ARCA.SERVER.HOST.exe");
DateTime dateTime = GetBuildDate(assembly);
Console.WriteLine(dateTime);
728x90
▶ Assembly 클래스 : 어셈블리 빌드 날짜 구하기
using System;
using System.IO;
using System.Reflection;
#region 빌드 날짜 구하기 - GetBuildDate(assembly)
/// <summary>
/// 빌드 날짜 구하기
/// </summary>
/// <param name="assembly">어셈블리</param>
/// <returns>빌드 날짜</returns>
public DateTime GetBuildDate(Assembly assembly)
{
string location = assembly.Location;
const int HEADER_OFFSET = 60;
const int LINKER_TIMESTAMP_OFFSET = 8;
byte[] bufferArray = new byte[2048];
Stream stream = null;
try
{
stream = new FileStream(location, FileMode.Open, FileAccess.Read);
stream.Read(bufferArray, 0, 2048);
}
finally
{
if(stream != null)
{
stream.Close();
}
}
int index = BitConverter.ToInt32(bufferArray, HEADER_OFFSET);
int secondCountSince1970 = BitConverter.ToInt32(bufferArray, index + LINKER_TIMESTAMP_OFFSET);
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0);
dateTime = dateTime.AddSeconds(secondCountSince1970);
dateTime = dateTime.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dateTime).Hours);
return dateTime;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] Encoding 클래스 : 유니코드 문자열 여부 구하기 (0) | 2020.02.29 |
---|---|
[C#/COMMON] Regex 클래스 : Matches 메소드를 사용해 단어 수 구하기 (0) | 2020.02.29 |
[C#/COMMON] List<T> 클래스 : AsReadOnly 메소드를 사용해 읽기 전용 컬렉션 만들기 (0) | 2020.02.29 |
[C#/COMMON] Environment 클래스 : Exit 정적 메소드를 사용해 콘솔 애플리케이션 종료하기 (0) | 2020.02.29 |
[C#/COMMON] Process 클래스 : Start 정적 메소드를 사용해 파일 탐색기 실행하기 (0) | 2020.02.29 |
[C#/COMMON] Assembly 클래스 : 어셈블리 빌드 날짜 구하기 (0) | 2020.02.29 |
[C#/COMMON] 디렉토리 복사하기 (0) | 2020.02.29 |
[C#/COMMON] PropertyInfo 클래스 : 속성 값 설정하기 (0) | 2020.02.29 |
[C#/COMMON] Regex 클래스 : 부적절한 파일명 문자 제거하기 (0) | 2020.02.29 |
[C#/COMMON] ManagementObjectSearcher 클래스 : 윈도우즈 제품명 구하기 (0) | 2020.02.29 |
[C#/COMMON] Dictionary<TKey, TValue> 클래스 : 정렬하기 (0) | 2020.02.29 |
댓글을 달아 주세요