Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to get format of date time from my system.
i will either shortdate or longdate.

What I have tried:

string sysFormat = CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern;
Posted
Updated 12-May-17 0:58am
v2

What about
C#
string sDate = DateTime.Now.ToShortDateString(); // get current date as 'short date' formatted string
?
 
Share this answer
 
Comments
Vibhusha Devani 12-May-17 6:07am    
My system formate is dd-MMM-yy.

on my and your code it get all time "dd-mm-yy" like this 12/05/2017.

if i will change formate on my system then also it gives same formate "dd-mm-yy" at all time.
CPallini 12-May-17 6:51am    
Then you probably have to call
DateTime.Now.ToString("dd-MMM-yy", System.Globalization.CultureInfo.CurrentCulture);
Vibhusha Devani 13-May-17 1:14am    
yes it's right but my requirement is when i change my date time format on my pc then that changed format i have to get on my windows application.
Member 14060363 22-Feb-21 1:04am    
if you have got the answer please help here
Member 15073686 22-Feb-21 4:56am    
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 system_date_and_time_format
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Start();
}

private void Form1_Load(object sender, EventArgs e)
{

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 HH:mm:ss tt", "dd-MMM-yyyy HH:mm:ss tt", "dd-MM-yyyy" };
MessageBox.Show(myDateTimeFormat[0].ToString());
for(int j =0;j
C#
string now = DateTime.Now.ToString("dd-MM-yyyy")

- is a delimiter you can change with whatever character you like.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900