Groups | Blog | Home
all groups > c# > november 2006 >

c# : String format...


karthee
11/28/2006 9:23:05 PM
i have this structure...

struct tFullTime
{
public int Year;
public int Month;
public int Day;
public int Hour;
public int Min;
public int Sec;
public int Hun;
} tSrcTime;


this is C++ code....

CString sReturn;
sReturn.Format( "%02d:%02d:%02d - %02d/%02d/%02d",
tSrcTime.Hour,
tSrcTime.Min,
tSrcTime.Sec,
tSrcTime.Month,
tSrcTime.Day,
tSrcTime.Year);

how to format strings like this in C#.NET?
Michael C
11/29/2006 12:00:00 AM
[quoted text, click to view]

I generally don't use this method and just concatenate the string myself but
I believe you can do string.Format(....) in pretty much the same way. It is
a static function of the string class.

[quoted text, click to view]

Morten Wennevik
11/29/2006 12:00:00 AM
Hi,

Considering you are basically working with a DateTime object, why not
scrap fFullTime and use DateTime instead?
To format your date and time simply do DateTime.ToString("hh:mm:ss -
MM/dd/yy"). You could also use DateTime.ToString() for the default output
(culture specific).

The / in DateTime.ToString also has a special meaning, which may be
culture specific. On my system I had to do @"hh:mm:ss - MM\/dd\/yy" to be
able to display as 11/29/06.




On Wed, 29 Nov 2006 06:23:05 +0100, karthee <kartheeknagasuri@gmail.com>
[quoted text, click to view]



--
Happy Coding!
Hooyoo
11/29/2006 3:11:45 AM

[quoted text, click to view]

string return = String.Format("{0:00}:{1:00}:{2:00} -
{3:00}/{4:00}/{5:00}",
tSrcTime.Hour,
tSrcTime.Min,
tSrcTime.Sec,
tSrcTime.Month,
tSrcTime.Day,
tSrcTime.Year);
Other guys totally lost.
AddThis Social Bookmark Button