Quick question - formatting the way time is displayed

G

Gary

f.CreationTime.Hour.ToString() + ":" +
f.CreationTime.Minute.ToString() + ":"
+ f.CreationTime.Millisecond.ToString();

Which produces a format like 9:30:124

Now I'd like to change this slightly. Firstly I do not need to know the
creation time of the file accurate to the thousandths of miliseconds!
So would prefer to have something like:

9:30:12

Secondly I'd like to append am/pm to the time, to give something like:
-

9:30:12 am

Can someone tell me how to modify the above original code to produce an
output more like the example directly above?

Thanks,

Gary.
 
O

Otis Mukinfus

f.CreationTime.Hour.ToString() + ":" +
f.CreationTime.Minute.ToString() + ":"
+ f.CreationTime.Millisecond.ToString();

Which produces a format like 9:30:124

Now I'd like to change this slightly. Firstly I do not need to know the
creation time of the file accurate to the thousandths of miliseconds!
So would prefer to have something like:

9:30:12

Secondly I'd like to append am/pm to the time, to give something like:
-

9:30:12 am

Can someone tell me how to modify the above original code to produce an
output more like the example directly above?

Thanks,

Gary.

Formatting can be done like this:

I don't think you can resolve to one thousandth of a millisecond, but you can
resolve to milliseconds, although I don't think you will actually get the exact
milliseconds.

string.Format("{0:H:mm:ss:ffff tt}", DateTime.Now)

I don't see that you used the seconds, which kind of makes the milliseconds
value meaningless. I added that one for you.

Look at string format in the documentation. You will find a kazillion ways to
format a DateTime object.


Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 

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

Top