14 December 2011

C# Lesson 14 : Working with DateTime

Like strings, dates and times are represented using special types and so deserve some attention. In this lesson, we learn how to work with Date and Time data, how to create new instances of DateTime, how to add time, and how to format the data for display. We also discuss the TimeSpan class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatesAndTimes
    class Program
        static void Main(string[] args)
            DateTime myValue = DateTime.Now;




            //DateTime myBirthday = new DateTime(1969, 12, 7);

            DateTime myBirthday = DateTime.Parse("12/7/1969");
            TimeSpan myAge = DateTime.Now.Subtract(myBirthday);

Source : MS Virtual Academy
Post a Comment