Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Time in C#?
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01576867
Message ID:
01576947
Views:
60
This message has been marked as a message which has helped to the initial question of the thread.
>This seems to work nicely, but how to get AM/PM as a string?
>
>
>DateTime dt;
>
>if (DateTime.TryParse("10:30 AM", out dt))
>{
>   Console.WriteLine (dt.Hour);
>   Console.WriteLine(dt.Minute);
>  ? Console.WriteLine(dt.);
>}
Either one of these should do the trick:
Console.WriteLine( dt.ToString("t"));
Console.WriteLine( dt.ToString("hh:mm tt"));
Using format strings has the additional advantage that they are locale aware - if you run this on a machine in Germany you get the local German format (which would be 24 hour clock instead of AM/PM).

+++ Rick ---
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Reply
Map
View

Click here to load this message in the networking platform