Date time to string and back to date time

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;          // this is the file which needed to be used//

namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        string s;
        public Form1()
        {
            InitializeComponent();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            s = dateTimePicker1.Value.ToString("o");
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dateTimePicker2.Value = DateTime.ParseExact(s, "o", CultureInfo.InvariantCulture);
        }
    }
}

Post a Comment