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

'  Filename: TestCTimeApp.bas
'
'  Compile: vbc TestCTimeApp.bas
'  Execute: TestCTimeApp

Imports System

Namespace MyTestApplication1

    Class TestCTimeApp
        Shared Dim weekNames() As String = New String() { _
                      "일", "월", "화", "수", "목", "금", "토"  _
                  }

        ' Java 언어의 main 메소드에 해당하는 Visual Basic의 Main
        Shared Sub Main(ByVal args() As String)
            Dim now As DateTime = DateTime.Now
            Dim StartOfEpoch As DateTime = New DateTime(1970, 1, 1)

            ' 1970년 1월 1일 0시 0분 0초부터 시작하여 현재까지의 초
            ' Console.WriteLine("UTC: " & (now.ToUniversalTime / 1000L) + "초")
            ' Console.WriteLine("UTC: " & DateTime.UtcNow + "초")
            ' Console.WriteLine("UTC: " & TimeZoneInfo.ConvertTimeToUTC(now) + "초")
            ' Console.WriteLine("UniversalTime  :" & System.TimeZone.CurrentTimeZone.ToUniversalTime(now))
            ' Console.WriteLine("UniversalTime  :" & (DateTime.UtcNow - StartOfEpoch).TotalMilliseconds)
            Console.WriteLine("UTC: " & Convert.ToInt64((DateTime.UtcNow - StartOfEpoch).TotalMilliseconds / 1000L) & "초")


            ' 현재 시각 표시: 20xx년 xx월 xx일 (x요일) xx시 xx분 xx초
            Console.Write(now.Year & "년 ")
            Console.Write(now.Month & "월 ")   ' Not 1 + now.Month !!
            Console.Write(now.Day & "일 ")
            Console.Write("(" + weekNames(Int(now.DayOfWeek)) & "요일) ")
            Console.Write(now.Hour & "시 ")
            Console.Write(now.Minute & "분 ")
            Console.WriteLine(now.Second & "초")

            ' 1월 1일은 1, 1월 2일은 2
            Console.Write("올해 몇 번째 날: " & now.DayOfYear & ", ")

            ' True 이면 서머타임 있음
            Dim tmp As String
            If Not now.IsDaylightSavingTime() Then tmp = "안함" Else tmp = "함"
            Console.WriteLine("서머타임 적용 여부: " & tmp)
        End Sub
    End Class
End Namespace




컴파일> vbc TestCTimeApp.bas

실행> TestCTimeApp
UTC: 1234542427
2009년 2월 14일 (토요일) 1시 27분 6초
올해 몇 번째 날: 45, 서머타임 적용 여부: 안함



크리에이티브 커먼즈 라이선스
Creative Commons License

 



Posted by Scripter
,