Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Time in C#?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01576867
Message ID:
01576947
Vues:
58
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?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform