find and solve || findandsolve.com
Please wait.....

Welcome back.






Before Read Terms of use

DateTime Format or DateTime Structure In C#

DateTime Format or DateTime Structure In C#


Date Formate in  C#

The DateTime data type use in C# date and time. It’s provides properties and methods to format dates in different datetime formats in C#. Here is some example and describes various date time formats and their results.

Format Result
DateTime.Now.ToString("dddd, dd MMMM yyyy") Monday, 21 October 2019
DateTime.Now.ToString("dddd, dd MMMM yyyy") Monday, 21 October 2019 
DateTime.Now.ToString("MM/dd/yyyy") 10/21/2019
DateTime.Now.ToString("dddd, dd MMMM yyyy")     Monday, 21 October 2019 10:50 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy")     Monday, 21 October 2019 6:40
DateTime.Now.ToString("dddd, dd MMMM yyyy")     Monday, 21 October 2019 6:40 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss") Monday, 21 October 2019 10:50:06
DateTime.Now.ToString("MM/dd/yyyy HH:mm") 10/21/2019 10:50
DateTime.Now.ToString("MM/dd/yyyy hh:mm tt") 10/21/2019 10:50 AM
DateTime.Now.ToString("MM/dd/yyyy H:mm") 10/21/2019 6:40
DateTime.Now.ToString("MM/dd/yyyy h:mm tt") 10/21/2019 6:40 AM
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") 10/21/2019 10:50:06
DateTime.Now.ToString("MMMM dd") October 21
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK") 2019-10-16T10:50:06.7199222-04:00
DateTime.Now.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’") Mon, 16 Oct 2019 10:50:06 GMT
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss") 2019-10-16T10:50:06
DateTime.Now.ToString("HH:mm") 10:50
DateTime.Now.ToString("hh:mm tt")    10:50 AM
DateTime.Now.ToString("H:mm") 6:40
DateTime.Now.ToString("h:mm tt") 6:40 AM
DateTime.Now.ToString("HH:mm:ss") 10:50:06
DateTime.Now.ToString("yyyy MMMM") 2019 October


 

 Format Description 


  • m = Minutes 
  • mm =Minutes with a leading zero
  • M =Month number(like,2)
  • MM =Month number with leading zero(eg.03)
  • MMM =Abbreviated Month Name (like,  Oct)
  • MMMM =Full month name (like,  October)
  • d = Represents the day of the month as a number from 1 through 31.
  • dd = Represents the day of the month as a number from 1 through 31.
  • ddd = Represents the abbreviated name of the day (like, Sun,Mon, Tues).
  • dddd = Represents the full name of the day (Sunday, Monday, like that).
  • y = Year, no leading zero (like,  2019 would be 18)
  • yy = Year, leading zero (like,  2019 would be 018)
  • yyy = Year, (like,2019)
  • yyyy = Year, (like,  2019)
  • h =12 hour clock hour (like, 7).
  • hh =12-hour clock, with a leading 0 (like, 05)
  • H =24-hour (like,  16)
  • HH =24-hour, with a leading 0 (like, 22)
  • s =Seconds
  • ss = Seconds with leading zero
  • t = Abbreviated AM / PM (like, A or P)
  • tt =AM / PM (like, AM or PM)
  • y =Year, no leading zero (like, 2019 would be 19)
  • yy =Year, leading zero (like,2019 would be 019)
  • yyy =Year, (like,2019)
  • yyyy = Year, (like,2019)
  • K =Represents the time zone information(like,6:40)
  • z = DateTime values, represents the signed offset of the local operating system's time zone. Universal Time (UTC) (like, +5)
  • zz = As z, but with leading zero (like, +05)
  • zzz = DateTime values, represents the signed offset of the local operating system's time zone from UTC(like, +05:00)
  • ffff = Represents the seven most significant digits of the seconds fraction.

 Here is a completed  DateTime format example
 

 using System;

    public class Program
    {
        public static void Main()
        {
            // Get current DateTime 
            DateTime datetimeExample = DateTime.Now;

            // Display different DateTime formats  
            Console.WriteLine(datetimeExample.ToString("MM/dd/yyyy"));
            Console.WriteLine(datetimeExample.ToString("dddd, dd MMMM yyyy"));
            Console.WriteLine(datetimeExample.ToString("dddd, dd MMMM yyyy"));
            Console.WriteLine(datetimeExample.ToString("dddd, dd MMMM yyyy"));
            Console.WriteLine(datetimeExample.ToString("dddd, dd MMMM yyyy"));
            Console.WriteLine(datetimeExample.ToString("dddd, dd MMMM yyyy"));
            Console.WriteLine(datetimeExample.ToString("dddd, dd MMMM yyyy HH:mm:ss"));
            Console.WriteLine(datetimeExample.ToString("MM/dd/yyyy HH:mm"));
            Console.WriteLine(datetimeExample.ToString("MM/dd/yyyy hh:mm tt"));
            Console.WriteLine(datetimeExample.ToString("MM/dd/yyyy H:mm"));
            Console.WriteLine(datetimeExample.ToString("MM/dd/yyyy h:mm tt"));
            Console.WriteLine(datetimeExample.ToString("MM/dd/yyyy HH:mm:ss"));
            Console.WriteLine(datetimeExample.ToString("MMMM dd"));
            Console.WriteLine(datetimeExample.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK"));
            Console.WriteLine(datetimeExample.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’"));
            Console.WriteLine(datetimeExample.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss"));
            Console.WriteLine(datetimeExample.ToString("HH:mm"));
            Console.WriteLine(datetimeExample.ToString("hh:mm tt"));
            Console.WriteLine(datetimeExample.ToString("H:mm"));
            Console.WriteLine(datetimeExample.ToString("h:mm tt"));
            Console.WriteLine(datetimeExample.ToString("HH:mm:ss"));
            Console.WriteLine(datetimeExample.ToString("yyyy MMMM"));
        }
    }

 
Output different DateTime Formats in c#

10/22/2019
Tuesday, 22 October 2019
Tuesday, 22 October 2019
Tuesday, 22 October 2019
Tuesday, 22 October 2019
Tuesday, 22 October 2019
Tuesday, 22 October 2019 10:00:02
10/22/2019 10:00
10/22/2019 10:00 AM
10/22/2019 10:00
10/22/2019 10:00 AM
10/22/2019 10:00:02
October 22
2019’-‘10’-‘22’T’10’:’00’:’02.8400539+00:00
Tue, 22 Oct 2019 10’:’00’:’02 ‘G10T’
2019’-‘10’-‘22’T’10’:’00’:’02
10:00
10:00 AM
10:00
10:00 AM
10:00:02
2019 October
 

 

Sundar  Neupane

Sundar Neupane

I like working on projects with a team that cares about creating beautiful and usable interfaces.

Comments



Report Response