반응형

* VBNET DateTimeFormat yyyy-MM-dd HH:mm:ss - 전역 설정 예제...

 

Main

전체 소스 코드

Form1.vb

 

Imports System.Globalization
Imports System.Threading

Public Class Form1

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)

        '전역 설정...
        Dim cti As CultureInfo = CType(CultureInfo.CurrentCulture.Clone(), CultureInfo)
        cti.DateTimeFormat.LongDatePattern = "yyyy-MM-dd"
        cti.DateTimeFormat.LongTimePattern = "HH:mm:ss"
        cti.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"
        cti.DateTimeFormat.ShortTimePattern = "HH:mm:ss"
        Thread.CurrentThread.CurrentUICulture = cti
        Thread.CurrentThread.CurrentCulture = cti

    End Sub


    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        '전역 설정 했을 경우 2020-03-19 21:47:54 로 나타남.
        '하지 않았을 경우 2020-03-19 오후 9:47:54.
        label1.Text = DateTime.Now.ToString()
        'label1.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
    End Sub
End Class

 

*예제 결과

 

 

반응형

+ Recent posts