반응형

* C# DateTime Format yyyy-MM-dd HH:mm:ss - 전역 설정 예제...

 

Main

 

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Globalization;
using System.Threading;

namespace CSharp_GlobalDateTimeFormat
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //전역 설정...
            CultureInfo cti = CultureInfo.CurrentCulture.Clone() as 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";
            System.Threading.Thread.CurrentThread.CurrentCulture = cti;
            System.Threading.Thread.CurrentThread.CurrentUICulture = cti;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //전역 설정 했을 경우 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");
        }
    }
}

 

 

*예제 결과

 

반응형

+ Recent posts