Tech Off Post

Single Post Permalink

View Thread: Question regarding DateTime
  • User profile image
    rmf919

    If I wanted to send a countdown app (example below, taken from channel 9) to someone in France, how would I convert the date to the proper format?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
    
            static void Main(string[] args)
                 
    
                /* If you want to use this file to tell someone happy birthday,
                 * all you must do is change the "OPEN THIS...", the birthDay value,
                 * and the names, telling who's birthday it is and who it is from.
                 */
    
            {
                // The Information at the top of the Console
                Console.WriteLine("O P E N   T H I S   P R O G R A M   2 0 1 2");
                Console.WriteLine("===========================================");
    
                
    
                //The Variables and Data Types
                DateTime rightNow = DateTime.Now.Date;
                DateTime birthDay = DateTime.Parse("01/28/2012");
                TimeSpan daysLeft = birthDay.Subtract(DateTime.Now);
    
                //If Today is his birthday
                if (rightNow == birthDay)
                {
    
                    Console.WriteLine("Happy Birthday Papa!\n \n From: name");
                    Console.WriteLine("======================================");
                    Console.ReadLine();
                }
                    // If his bithday has already passed
                else if (rightNow > birthDay)
                {
                    Console.WriteLine("Sorry, but this program is valid for this year only.  This program is no longer of  any use, you may delete it.");
                    Console.ReadLine();
                }
                    //If his birthday hasn't quite made it here yet
                else
                {
    
                    Console.WriteLine("Sorry, but you must wait " + daysLeft.Days + " days, then open this file. \n");
                    Console.WriteLine("It is currently: " + DateTime.Now);
                    Console.ReadLine();
                }
            }
        }
    }

     

    I realize this is a bit of a redundant question (why not write as 28/01/2012?). I'm just trying to experiment with the capabilities of DateTime.