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.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Globalization;  
  8. using System.Windows.Forms;  
  9.   
  10. namespace SystemDateTimeCheck  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.         private void Form1_Load(object sender, EventArgs e)  
  19.         {  
  20.             // Get the Current System culture.  
  21.             CultureInfo ci = CultureInfo.CurrentCulture;  
  22.             DateTimeFormatInfo dtfi = ci.DateTimeFormat;  
  23.             string[] SystemDateTimePatterns = new string[250];  
  24.             int i = 0;  
  25.             foreach (string name in dtfi.GetAllDateTimePatterns('d'))  
  26.             {  
  27.                 SystemDateTimePatterns[i] = name;  
  28.                 i++;  
  29.             }  
  30.             string[] myDateTimeFormat = { "dd-MMM-yy""dd-MMM-yyyy" };  
  31.             if (myDateTimeFormat[0].Equals(SystemDateTimePatterns[0]) || myDateTimeFormat[1].Equals(SystemDateTimePatterns[0]))  
  32.                 MessageBox.Show("Your System DateTime Format " + SystemDateTimePatterns[0] + " is OK");  
  33.             else  
  34.                 MessageBox.Show("Your System DateTime Format is: " + SystemDateTimePatterns[0] + "\n" + "Required DateTime Format: dd-MMM-yy Or dd-MMM-yyyy");  
  35.         }  
  36.     }  
  37. }


Similar Articles