Results 1 to 4 of 4

Thread: Convert datetime to small date in C#

  1. #1
    Join Date
    Mar 2009
    Posts
    8

    Convert datetime to small date in C#

    I am learning C# in that i want Convert datetime to small date format. I tried to do it but not completed can some one help me ?

    Thanks

  2. #2
    Join Date
    Oct 2008
    Posts
    20

    Re: Convert datetime to small date in C#

    You can Format time and date by using following code

    Code:
    using System;  
      
    class MainClass {  
      public static void Main() {  
        DateTime dt = DateTime.Now; 
     
        Console.WriteLine("Time is {0:hh:mm tt}", dt); 
      } 
    }

  3. #3
    Join Date
    Oct 2008
    Posts
    73

    Re: Convert datetime to small date in C#

    To convert a string-based date to a System .DateTime object, you can use the Convert.ToDateTime(String) method or the DateTime.Parse static methodthod.

    Eg.

    Code:
    // Date strings are interpreted according to the current culture.
    // If the culture is en-US, this is interpreted as "January 8, 2008",
    // but if the user's computer is fr-FR, this is interpreted as "August 1, 2008"
    string date = "01/08/2008";
    DateTime dt = Convert.ToDateTime(date);            
    Console.WriteLine("Year: {0}, Month: {1}, Day: {2}", dt.Year, dt.Month, dt.Day);
    
    // Specify exactly how to interpret the string.
    IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
    
    // Alternate choice: If the string has been input by an end user, you might 
    // want to format it according to the current culture:
    // IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
    DateTime dt2 = DateTime.Parse(date, culture, System.Globalization.DateTimeStyles.AssumeLocal);
    Console.WriteLine("Year: {0}, Month: {1}, Day {2}", dt2.Year, dt2.Month, dt2.Day);
    
    /* Output (assuming first culture is en-US and second is fr-FR):
        Year: 2008, Month: 1, Day: 8
        Year: 2008, Month: 8, Day 1
     */

  4. #4
    Join Date
    Dec 2008
    Posts
    40

    Re: Convert datetime to small date in C#

    Console.WriteLine("{0}/{1}/{2}", DateTime.Now.ToString("dd"), DateTime.Now.ToString("MM"), DateTime.Now.ToString("yy"))

Similar Threads

  1. How to convert UTC timestamp value to date and time
    By AsceTic! in forum MS Office Support
    Replies: 2
    Last Post: 02-02-2012, 07:14 PM
  2. How to convert DateTime to Date and vice versa in c#?
    By Madaleno in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 09:35 PM
  3. How to convert string into DateTime
    By Segvoia in forum Software Development
    Replies: 7
    Last Post: 05-03-2010, 02:55 PM
  4. How to convert date format in postgres
    By Sayam in forum Software Development
    Replies: 3
    Last Post: 18-03-2009, 11:08 PM
  5. Convert Hex Value to Date from Binary Reg Key
    By RobT in forum Windows Server Help
    Replies: 4
    Last Post: 01-04-2005, 11:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,449,372.26789 seconds with 17 queries