WHAT IS A BASIC CONCEPT OF DATE AND TIME

Ailsa Singh

Total Post:24

Points:168
Posted by  Ailsa Singh
C# 
C#
 657  View(s)
Ratings:
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.

Thanks
  1. Elena Glibart

    Post:42

    Points:296
    Re: What is a basic concept of date and time


    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,

                                                  TimeSpan.Zero);

     

     

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

     

    H: Hour

    mm:Minute

    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}", 
                       Date2);

    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);
                Console.ReadLine();
     
            }
        }
    }
     
     
     

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!