C#
  Home arrow C# arrow Page 3 - C# Simplified, part 3
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

C# Simplified, part 3
By: Anand Narayanaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 11
    2005-05-17

    Table of Contents:
  • C# Simplified, part 3
  • Displaying numbers in different formats
  • Display date and time in different formats
  • Arrays
  • Using Array.Rank
  • Enumerations

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    C# Simplified, part 3 - Display date and time in different formats


    (Page 3 of 6 )

    You can display data and time in different ways with the help of DateTime format specifiers. Listing 3.4 explains each one of these specifiers in detail. I have given necessary explanations in the form of comments.

    Listing 3.4

    using System;

    class DateTimeFormat

    {

    public static void Main()

    {

    DateTime dt = DateTime.Now;

    // Returns Short Date (MM/DD/YYYY)

    Console.WriteLine("Format Specifier (d): {0:d}",dt);

    // Returns Long Date (Day, Month Date, Year)

    Console.WriteLine("Format Specifier (D): {0:D}",dt);

    // Returns Full Date with Time and without seconds

    Console.WriteLine("Format Specifier (f):{0:f}",dt);

    // Returns Full Date with Time and with Seconds

    Console.WriteLine("Format Specifier (F):{0:F}",dt);

    // Returns short date and short time without seconds

    Console.WriteLine("Format Specifier (g):{0:g}",dt);

    // Returns short date and short time with seconds

    Console.WriteLine("Format Specifier (G):{0:G}",dt);

    // Returns Month and Day - M can also be used

    Console.WriteLine("Format Specifier (m):{0:m}",dt);

    // Returns the date and time in RFC1123 format

    // r can also be used

    Console.WriteLine("Format Specifier (R):{0:R}",dt);

    // Returns Short Time

    Console.WriteLine("Format Specifier (t):{0:t}",dt);

    // Returns Short Time with Second

    Console.WriteLine("Format Specifier (T):{0:T}",dt);

    // Returns Year and Month - Y also can be used

    Console.WriteLine("Format Specifier (y):{0:y}",dt);

    }

    }

    The final output of the above code will look like Figure 3.4.

    Figure 3.4

    More C# Articles
    More By Anand Narayanaswamy


     

    C# ARTICLES

    - Working with Dates and Times in C#
    - Generics, Dictionaries, and More
    - More About Generics
    - Working with C# Collections
    - Generics
    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT