Posted by : Anwar Hossain
Category : asp.net c # basic tutorial

Custom Time formatting example C #

Dear viewers in this tutorial I will show how to format date and time using String.Format Method using ASP .Net C#. It can be said custom date and time formatting.In this example I have shown most common customizing date time pattern such as only time with minute using shorformat, time with minute and second using LongTime, LongDate with ShortTime, LongDate with Longtime, ShortDate with ShortTime, ShortDate with Longtime.

Custom Time formatting example C #

Common Time formatting example C #

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace DateTimeformat

{

 

    class Program

    {

        static void Main(string[] args)

        {

 

 

            DateTime dt = new DateTime(2014, 3, 9, 16, 5, 7, 123);

       

            Console.WriteLine("\nShow time with minute  using shorformat");

            Console.WriteLine("-----------------------------------");

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

 

            Console.WriteLine("\nShow time with minute and second  using LongTime");

            Console.WriteLine("-----------------------------------");

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

 

            Console.WriteLine("\nShow LongDate with ShortTime");

            Console.WriteLine("-----------------------------------");

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

 

            Console.WriteLine("\nShow LongDate with Longtime");

            Console.WriteLine("-----------------------------------");

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

 

            Console.WriteLine("\nShow ShortDate with ShortTime");

            Console.WriteLine("-----------------------------------");

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

 

 

            Console.WriteLine("\nShow ShortDate with Longtime");

            Console.WriteLine("-----------------------------------");

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

                

            Console.ReadLine();

           

        }

    }

   

  

}

 

 

 

Out Put

c-sharp-time-format-using-string-format-method



Realted Article Headline

How to find odd number in c #
How to generate random number in c #
Nested For Loop Example in C Sharp
Store C sharp reference type in a List C#
Find number of items in a List C#
Concept about C # List
Custom Time formatting example C #
Custom Date formatting example C #
String Format Example using ASP.Net C#
Simple enum example in C Sharp
Nested switch-case statement example in C #
Combined switch...case statement example in C #
C Sharp switch case statement Example
C# SUM ArrayList Element Example
C# String Class Methods Example
C Sharp String Class Properties and Methods
C Sharp String Class Example
How to join two ArrayList collections in C#.
How to Use C Sharp Math Class
C Sharp ArrayList Property and Method
C Sharp ArrayList Example
C Sharp Arrays Example
C Sharp Logical operator Example
C Sharp Relational operators
C Sharp Arithmetic operators Example
C Sharp Common Assignment Operator
Simple for loop example in c sharp

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection