This is most of the time sufficient when you need to format date/time.
DateTime.Now.ToString("dd-MMM-yyyy | hh:mm tt");
many times you need to convert string to Datetime and there might be some issues related to Regional settings, so in those cases an easy example is
DateTime dt = DateTime.Parse("11/16/2009 7:51:45 PM", new CultureInfo("en-US"));
==========
If you want to display string upto some decimal places always, do this
int tempInt = 24;
string tempStr = tempInt.ToString("D3");
Sunday, August 10, 2008
Convert total seconds into hour, minute and second
Many time we need to convert total seconds to Hour, Minute,second format. Here is a simple implementation.
int totalSecondsInt, tempH, tempM, tempS;
decimal totalSecondsDec = Convert.ToDecimal(totalSecondsInt);
tempH = Convert.ToInt32(totalSecondsDec / 3600);
tempM = Convert.ToInt32(Math.Floor(((totalSecondsDec / 3600) - Convert.ToInt16((totalSecondsDec / 3600))) * 60));
tempS = Convert.ToInt32(Math.Floor(totalSecondsDec % 60));
int totalSecondsInt, tempH, tempM, tempS;
decimal totalSecondsDec = Convert.ToDecimal(totalSecondsInt);
tempH = Convert.ToInt32(totalSecondsDec / 3600);
tempM = Convert.ToInt32(Math.Floor(((totalSecondsDec / 3600) - Convert.ToInt16((totalSecondsDec / 3600))) * 60));
tempS = Convert.ToInt32(Math.Floor(totalSecondsDec % 60));
Friday, August 8, 2008
my technical blog launched today
hi... I have started from today my technical blog. Here you will find technolgy things explained in a simple way :-)
Subscribe to:
Posts (Atom)