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