سؤال

How to separate date by "/" means 02/04/2014, I am getting output like this 02-04-2014, but I want like this:

4/2/2014
هل كانت مفيدة؟

المحلول

/ gets replaced by your culture's date separator which seems to be -.

Read: The "/" Custom Format Specifier:

The "/" custom format specifier represents the date separator, which is used to differentiate years, months, and days. The appropriate localized date separator is retrieved from the DateTimeFormatInfo.DateSeparator property of the current or specified culture.

You can use CultureInfo.InvariantCulture:

string dateAsString = DateTime.Now.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);

نصائح أخرى

you can use this sample

 DateTime now = DateTime.Now;
 Console.WriteLine(now.ToString("d"));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top