Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My system date format is dd-MM-yyyy(20-10-2012) and I'm getting the date and using separator to split the date, month and year. I need to convert date format (dd/MM/yyyy) whether the formats returns at any date format.

string sDate = string.Empty;
DateTime _date = DateTime.Now;
int count = 0;
string format = "dd-MM-yyyy";
sDate = dateFormat.ToString(format);
string[] Words = sDate.Split(new char[] { '-' });
foreach (string Word in Words)
{
    count += 1;
    if (count == 1) { Day = Word; }
    if (count == 2) { Month = Word; }
    if (count == 3) { Year = Word; }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
283 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is what you are looking for:

String sDate = DateTime.Now.ToString();
DateTime datevalue = (Convert.ToDateTime(sDate.ToString()));

String dy = datevalue.Day.ToString();
String mn = datevalue.Month.ToString();
String yy = datevalue.Year.ToString();

OR

Alternatively, you can use split function to split string date into day, month and year here.

Hope, it will helps you... Cheers. !!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...