As in title. I write a easy timer , which set time and date . Time works well , but date not.
It shows a year and a day , but not month . Why ?
My code:
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)
{
}
}
}
Result of this code :
time eg : 11:34:23
date eg : 20--2013
result must change to :
time eg : 11:34:23
date eg : 20/01/2013
Could you help me how to solve this problem ?
1 Answer