printing time in log messages

  • Thread starter Thread starter puzzlecracker
  • Start date Start date
P

puzzlecracker

I have this string string time =
System.DateTime.Now.ToLongTimeString(); it is equal to 1:00:22 PM

I need it to be 13:00:22

Any suggestions how to format it?

Thanks
 
I have this string  string time =
System.DateTime.Now.ToLongTimeString(); it is equal to 1:00:22 PM

I need it to be 13:00:22

Any suggestions how to format it?

Thanks

string.Format("{0:HH}:{1:mm}:{2:ss}", Now, Now, Now)

This is just one of many ways it can be done.
 
string.Format("{0:HH}:{1:mm}:{2:ss}", Now, Now, Now)

This is just one of many ways it can be done.

Argh, I don't think sting has Format member function :(
 
The page peter posted is the best reference. Personally I prefer

System.DateTime.Now.ToString("HH:mm:ss");

our systems are in UTC

System.DateTime.UTCNow.ToString("HH:mm:ss");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top