-1-
-2-
كل شئ عن التاريخ والوقت فى سى شارب Date and time in c sharp
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 wfa0038
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string stdt;
stdt = DateTime.Now.ToString();
label1.Text = stdt;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
string stdt;
stdt = DateTime.Now.ToString();
label2.Text = stdt;
}
private void button1_Click(object sender, EventArgs e)
{
DateTime stdt;
stdt = Convert.ToDateTime(" 13/04/1998 05:15:40 AM");
button1.Text = stdt.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox4.Visible = false;
richTextBox1.Visible = true;
richTextBox2.Visible = false;
richTextBox3.Visible = false;
string stdt2 = DateTime.Now.ToString("d");
string stdt3 = DateTime.Now.ToString("D");
string stdt4 = DateTime.Now.ToString("dddd");
string stdt5 = DateTime.Now.ToString("dddd-dd-MMMM-yyyy");
string stdt6 = DateTime.Now.ToString("t");
string stdt7 = DateTime.Now.ToString("T");
string stdt8 = DateTime.Now.ToString("dd ");
button2.Text = stdt2;
button3.Text = stdt3;
button4.Text = stdt4;
button5.Text = stdt5;
button6.Text = stdt6;
button7.Text = stdt7;
button8.Text = stdt8;
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
richTextBox4.Visible = false;
richTextBox1.Visible = false;
richTextBox2.Visible = true;
richTextBox3.Visible = false;
string stdt2 = DateTime.Now.ToString("MM");
string stdt3 = DateTime.Now.ToString("yyyy");
string stdt4 = DateTime.Now.ToString("yy");
string stdt5 = DateTime.Now.ToString("M");
string stdt6 = DateTime.Now.ToString("y");
string stdt7 = DateTime.Now.ToString("dd/MM/yyyy");
string stdt8 = DateTime.Now.ToString("dd / MM / yy" );
button2.Text = stdt2;
button3.Text = stdt3;
button4.Text = stdt4;
button5.Text = stdt5;
button6.Text = stdt6;
button7.Text = stdt7;
button8.Text = stdt8;
}
private void richTextBox2_TextChanged(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
richTextBox4.Visible = false;
richTextBox1.Visible = false;
richTextBox2.Visible = false;
richTextBox3.Visible = true;
string stdt2 = DateTime.Now.ToString("d/M/yyy");
string stdt3 = DateTime.Now.ToString("hh");
string stdt4 = DateTime.Now.ToString("mm");
string stdt5 = DateTime.Now.ToString("ss");
string stdt6 = DateTime.Now.ToString("hh:mm:ss");
string stdt7 = DateTime.Now.ToString("dd/MM/yyyy");
string stdt8 = DateTime.Now.ToString("dd / MM / yy");
button2.Text = stdt2;
button3.Text = stdt3;
button4.Text = stdt4;
button5.Text = stdt5;
button6.Text = stdt6;
button7.Text = stdt7;
button8.Text = stdt8;
}
private void richTextBox3_TextChanged(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
richTextBox1.Visible = false;
richTextBox2.Visible = false;
richTextBox3.Visible = false;
richTextBox4.Visible = true;
string stdt2 = DateTime.Now.ToString("tt");
string stdt3 = DateTime.Now.ToString("hh:mm:ss tt");
string stdt4 = DateTime.Now.ToString("dd/MM/yyyy -hh:mm:ss tt ");
string stdt5 = DateTime.Now.Date.ToString();
string stdt6 = DateTime.Now.Day.ToString();
string stdt7 = DateTime.Now.Month.ToString();
string stdt8 = DateTime.Now.Year.ToString();
//string stdt8 = DateTime.Now.Hour.ToString();
//string stdt8 = DateTime.Now.Minut.ToString();
//string stdt8 = DateTime.Now.Second.ToString();
button2.Text = stdt2;
button3.Text = stdt3;
button4.Text = stdt4;
button5.Text = stdt5;
button6.Text = stdt6;
button7.Text = stdt7;
button8.Text = stdt8;
}
private void button9_Click(object sender, EventArgs e)
{
string stdt9 = DateTime.Now.AddDays((double)numericUpDown3.Value).ToString();
button9.Text = stdt9;
}
private void button10_Click(object sender, EventArgs e)
{
string stdt10 = DateTime.Now.AddYears((int)numericUpDown1.Value).AddMonths((int)numericUpDown2.Value).AddDays((double)numericUpDown3.Value).AddHours((double)numericUpDown4.Value).AddMinutes((double)numericUpDown5.Value).ToString();
button10.Text = stdt10;
}
private void button11_Click(object sender, EventArgs e)
{
string stdt11 = DateTime.Now.AddYears((int)numericUpDown1.Value).AddMonths((int)numericUpDown2.Value).AddDays((double)numericUpDown3.Value).AddHours((double)numericUpDown4.Value).AddMinutes((double)numericUpDown5.Value).ToString("dddd dd / MMMM / yyyy - hh:mm: ss tt ");
button11.Text = stdt11;
}
private void button12_Click(object sender, EventArgs e)
{
DateTime stdt;
stdt = Convert.ToDateTime("01/01/2020");
// button12.Text = stdt.ToString("MM"); // 04 05
button12.Text = stdt.ToString("MMM"); //APR MAY
//button12.Text = stdt.ToString("MMMM"); APRIL MAY
string allmonth = "";
for (int i = 0; i < 12; i++)
{
allmonth += stdt.ToString("MM - MMMM") + "\n";
stdt = stdt.AddMonths(1);
}
MessageBox.Show(allmonth);
}
private void button13_Click(object sender, EventArgs e)
{
DateTime stdt;
stdt = Convert.ToDateTime("01/01/2020");
//button13.Text = stdt.ToString("dd");
button13.Text = stdt.ToString("ddd");
//button13.Text = stdt.ToString("dddd");
string allmonth = "";
for (int i = 0; i < 7; i++)
{
stdt = stdt.AddDays(1);
if (stdt.ToString("dddd")=="Saturday")
{
break;
}
}
for (int i = 0; i < 7; i++)
{
allmonth += stdt.ToString("dd -dddd") + "\n";
stdt = stdt.AddDays(1);
}
MessageBox.Show(allmonth);
}
private void button14_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
this.Hide();
}
}
}
-3-
-4-