System Date Time Check Format


This program executes the system date time format. Is it in dd/mmm/yyyy or other format and the which cultuerInfo is the system running on.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Globalization;

using System.Windows.Forms;

 

namespace SystemDateTimeCheck

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            // Get the Current System culture.

            CultureInfo ci = CultureInfo.CurrentCulture;

            DateTimeFormatInfo dtfi = ci.DateTimeFormat;

 

            string[] SystemDateTimePatterns = new string[250];

            int i = 0;

            foreach (string name in dtfi.GetAllDateTimePatterns('d'))

            {

                SystemDateTimePatterns[i] = name;

                i++;

            }

 

            string[] myDateTimeFormat = { "dd-MMM-yy", "dd-MMM-yyyy" };

            if (myDateTimeFormat[0].Equals(SystemDateTimePatterns[0]) || myDateTimeFormat[1].Equals(SystemDateTimePatterns[0]))

                MessageBox.Show("Your System DateTime Format " + SystemDateTimePatterns[0] + " is OK");

            else

                MessageBox.Show("Your System DateTime Format is: " + SystemDateTimePatterns[0] + "\n" + "Required DateTime Format: dd-MMM-yy Or dd-MMM-yyyy");

        }

    }

}

Up Next
    Ebook Download
    View all
    Learn
    View all