달력

12025  이전 다음

  • 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
  • 31
반응형


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
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Program program = new Program();                                                               
            Console.WriteLine("유닉스 시간에서 윈도우 : " 
                        + program.ConvertFromUnixTimestamp(1417141032));
            Console.WriteLine("윈도우 시간에서 유닉스 : "
                              + program.ConvertToUnixTimestamp(DateTime.Now));
            Console.Read();
        }
      
        private DateTime ConvertFromUnixTimestamp(double timestamp)
        {
            DateTime origin = new DateTime(1970110000);
            return origin.AddSeconds(timestamp);
        }
 
        private double ConvertToUnixTimestamp(DateTime date)
        {
            DateTime origin = new DateTime(1970110000);
            TimeSpan diff = date - origin;
            return Math.Floor(diff.TotalSeconds);
        }
    }
}
 
cs


실행


출처

http://codeclimber.net.nz/archive/2007/07/10/Convert-a-Unix-timestamp-to-a-NET-DateTime/

'프로그래밍 > C#' 카테고리의 다른 글

[C#]텍스트 읽어들이기  (0) 2018.07.17
[C#]동그란 이미지 만들기  (0) 2018.07.01
[C#] 텍스트를 픽쳐박스로...  (0) 2018.06.23
[C#]투명한 버튼  (0) 2018.06.16
[C#]AnimateWindow  (0) 2018.06.13
Posted by 유령회사
|