Oct 12, 2015

C# Basic ] date time











This post is date time.



I added text box for display datetime.

If press button '기록'(record) adding to list view.

Add new timer for datetime.

1
2
3
4
5
6
7
8
private void timer2_Tick(object sender, EventArgs e)
{
        get_time();
}
private void get_time()
{
        dateTimeText.Text = DateTime.Now.ToString();
}

'timer2_Tick()' call get_time() every 1 second.

'get_time()' is display date time. 

date time format is default 12 times

If you wan't format using DateTime.Now.ToString(your format);

This code is for press button '기록'(record)

1
2
3
4
5
ListViewItem lv = new ListViewItem(recordCnt.ToString());
lv.SubItems.Add(timerText.Text);
lv.SubItems.Add(dateTimeText.Text.ToString());
listView1.Items.Add(lv);
recordCnt++;

Run


every second refresh current date time.

press button '시작'(start) and '기록'(record).



※ P.S

Changing date time format.

1
dateTimeText.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
cs

I changing to format 24-times.


No comments:

Post a Comment