현재 시각을 컨솔에 보여주는 간단한 F# 언어 소스 코드이다.
UTC란 1970년 1월 1일 0시 0분 0초를 기준으로 하여 경과된 초 단위의 총 시간을 의미한다.
* UTC(Universal Time  Coordinated, 협정세계시, 協定世界時)


  1. (*
  2.  *  Filename: TestCTimeApp.fs
  3.  *
  4.  *  Compile: fsc --codepage:949 TestCTimeApp.fs
  5.  * 
  6.  *  Execute: TestCTimeApp 
  7.  *)
  8. // namespace MyTestApp1
  9. open System
  10. let weekNames = [| "일"; "월"; "화"; "수"; "목"; "금"; "토" |]
  11. let now = System.DateTime.Now
  12. let startOfEpoch = new DateTime ( 1970, 1, 1 )
  13. // 1970년 1월 1일 0시 0분 0초부터 시작하여 현재까지의 초
  14. printfn "UTC: %O" ((int64 (DateTime.UtcNow - startOfEpoch).TotalMilliseconds) / 1000L)
  15. // 현재 시각 표시: 20xx년 xx월 xx일 (x요일) xx시 xx분 xx초
  16. printf "%O년 " (now.Year)
  17. printf "%O월 " (now.Month)     // Not 1 + now.Month !!
  18. printf "%O일 " (now.Day)
  19. printf "(%O요일) " (weekNames.[int (now.DayOfWeek)])
  20. printf "%O시 " (now.Hour)
  21. printf "%O분 " (now.Minute)
  22. printfn "%O초" (now.Second)
  23. // 1월 1일은 1, 1월 2일은 2
  24. printf "올해 몇 번째 날: %O, " (now.DayOfYear)
  25. // True 이면 서머타임 있음
  26. let str = if not (now.IsDaylightSavingTime()) then "안함" else "함"
  27. printfn "서머타임 적용 여부: %O"  str



컴파일> fsc TestCTimeApp.fs

실행> TestCTimeApp
UTC: 1279016975
2010년 7월 13일 (화요일) 19시 29분 35초
올해 몇 번째 날: 194, 서머타임 적용 여부: 안함



Posted by Scripter
,