>  기사  >  백엔드 개발  >  C#에서 Unix 타임스탬프를 얻는 방법

C#에서 Unix 타임스탬프를 얻는 방법

WBOY
WBOY앞으로
2023-09-15 18:49:02791검색

如何在 C# 中获取 Unix 时间戳

Unix 타임스탬프는 주로 Unix 운영 체제에서 사용됩니다. 하지만 모두에게 도움이 됩니다 운영 체제는 모든 시간대의 시간을 나타냅니다.

Unix 타임스탬프는 시간을 초 단위로 나타냅니다. 유닉스 시대는 1일부터 시작된다 1970년 1월.

그래서 Unix 타임스탬프는 특정 날짜 사이의 초 수입니다.

Example

DateTime.Now.Subtract를 사용하여 Unix 타임스탬프()를 가져옵니다.총 초 DateTimeOffset.Now.ToUnixTimeSeconds()를 사용하여 Unix 타임스탬프를 가져오는

class Program{
   static void Main(string[] args){
      Int32 unixTimestamp = (Int32)(DateTime.Now.Subtract(new
      DateTime(1970, 1, 1))).TotalSeconds;
      Console.WriteLine("The Unix Timestamp is {0}", unixTimestamp);
      Console.ReadLine();
   }
}

Output

1596837896

Example

메서드

class Program{
   static void Main(string[] args){
      var unixTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
      Console.WriteLine("The Unix Timestamp is {0}.", unixTimestamp);
      Console.ReadLine();
   }
}

위 내용은 C#에서 Unix 타임스탬프를 얻는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제