String format...

  • Thread starter Thread starter karthee
  • Start date Start date
K

karthee

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?
 
karthee said:
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?

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.
 
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.
 
karthee said:
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?

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.
 
Back
Top