Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo
How to extract the time part from a DateTime datatype in C# (Thursday, August 19, 2004)
 
How to extract only the time from a DateTime datatype in C#

This example will show how to extract only the time from a DateTime datatype containing a date and a time in C#.

//C#
string strDateTime = "01/02/2002 11:30:12 AM";

// Displays 11:30 AM
Console.WriteLine(DateTime.Parse(strDateTime).ToShortTimeString());
// Displays 11:30:12 AM
Console.WriteLine(DateTime.Parse(strDateTime).ToLongTimeString());






Posted by Xander Zelders



 
Previous Posts
    - How to replace a line feed in a string with a <BR>...
    - How to get the content of an ASCII file into a tex...
    - How to read the content of an external website in ...
    - How to late bind an object, using the 'old' Prog.I...
    - How to parse an ASP.NET page.
    - How to determine wether a string fits in a textbox...
    - How to play sounds using the .NET framework
    - Howto convert strings from lower case to upper cas...
    - How to read images from an Access database (OLE ob...
    - How to Print from a rich text box

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland