如标题。我写了一个简单的计时器,它可以设置时间和日期。时间很好,但日期不行。它显示一年零一天,但不显示月份。为什么 ?
我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication_timer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
int h = DateTime.Now.Hour;
int m = DateTime.Now.Minute;
int s = DateTime.Now.Minute;
int d = DateTime.Now.Day;
int y = DateTime.Now.Year;
int t = DateTime.Now.Month;
label2.Text = DateTime.Now.ToString("dd/tt/yy");
label1.Text = DateTime.Now.ToString("hh:mm:ss");
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}
此代码的结果:
time eg : 11:34:23
date eg : 20--2013
结果必须更改为:
time eg : 11:34:23
date eg : 20/01/2013
你能帮我解决这个问题吗?