473,480 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Quick question - formatting the way time is displayed

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.

Jan 12 '07 #1
3 1619
Everything you need to know is here:

http://www.blackwasp.co.uk/CSharpDateManipulation.aspx

But the specific answer would be to rewrite it as:

f.CreationTime.ToString("h:mm:ss tt")
Gary wrote:
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.
Jan 12 '07 #2
Thankyou

Gary.

DeveloperX wrote:
Everything you need to know is here:

http://www.blackwasp.co.uk/CSharpDateManipulation.aspx

But the specific answer would be to rewrite it as:

f.CreationTime.ToString("h:mm:ss tt")
Gary wrote:
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.
Jan 12 '07 #3
On 12 Jan 2007 02:52:05 -0800, "Gary" <ga********@myway.comwrote:
>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
Jan 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
12005
by: Dimitri Furman | last post by:
Given: Access 2002/2003 A subform in datasheet or continuous view, placed on a tab page (this last may or may not matter) Conditional formatting applied to some controls on the subform - format...
4
2061
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.