Home > DeveloperSection > Forums > What is a basic concept of date and time
Ailsa Singh
Ailsa Singh

Total Post:24

Posted on    September-14-2016 4:08 AM

 C# C# 

 1 Reply(s)
 595  View(s)
Rate this:
I am implementing a project on c# programming language.I want to include  date and time in project.please help me.
I would really appreciate your help.


Elena Glibart
Elena Glibart

Total Post:42

Posted on    September-14-2016 4:13 AM

Here is a basic concept of data and time

* DateTime is the class which is already defined in the system.

* General format of the date is Year month and day.


                   For example: DateTime Date1 = new DateTime(2014, 02, 01);

In the above example below are the input which is already define by the programmer:

Year   : 2014

Month: (02) February

Day     :    01


* Representation of the date:

Programmer can represent the date in his/her own format by keeping the basic format in their mind


MMMM (in caps):- full name of the month. eg September

MMM (in caps):- short name of the month. eg. Sept

MM (in caps):- Month in number 


dddd (without caps) :- full name of the  day. eg Saturday

ddd (without caps) :- short name of the day. eg. Sat

dd (without caps)  :- day in number


yyy & yyyy (without caps) means :  represent year. ex. 2014

yy (without caps) : represent  last two alphabet of the year. ex for 2014 it will represent 14.


*In formatting operations, custom date and time format strings can be used either with the ToString method of a date and time instance or with a method that supports composite formatting.


* Syntax for the programmer to represent date in his/her own format.

Console.WriteLine("Today is " +Date1.ToString("ddd yy, MMMM") );



* DateTimeOffset is the class which is used for both date & time.

* General format of the date is Year, Month, Day, Hour, Minute, Second &  timespan.


For example DateTimeOffset Date2 = new DateTimeOffset(2011, 6, 10, 15, 24, 16,




*Programmer can represent the date in his/her own format by keeping the basic format in their mind 


H: Hour


ss : Second

zzz : TimeSpan  


* Syntax for the programmer to represent date & time  in his/her own format

Console.WriteLine (" date and time:{0:MM/dd/yy H:mm:ss zzz}", 

Here is the complete program to implement the date and time logic :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication12
    class Program
        static void Main(string[] args)
            DateTime date1 = new DateTime(2016,09,14);// year month and day
            Console.WriteLine("Today is " + date1.ToString("ddd yy, MMMM"));
            DateTimeOffset Date2 = new DateTimeOffset(2016,09,14, 15, 24, 16, new TimeSpan(1,0,0));
            Console.WriteLine(" date and time: {0:MM/dd/yy H:mm:ss zzz}", Date2);

Modified On Sep-14-2016 04:34:19 AM

Don't want to miss updates? Please click the below button!

Follow MindStick