Advertisement
jyoung12387

DateTime basics

Feb 25th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.  
  8.         DateTime moment = DateTime.Now;
  9.        
  10.         int year = moment.Year;
  11.         Console.WriteLine("Year: {0}", year);
  12.        
  13.         int month = moment.Month;
  14.         Console.WriteLine("Month: {0}", month);
  15.        
  16.         int day = moment.Day;
  17.         Console.WriteLine("Day: {0}", day);    
  18.        
  19.         int hour = moment.Hour;
  20.         Console.WriteLine("Hour {0}", hour);
  21.        
  22.         int minute = moment.Minute;
  23.         Console.WriteLine("Minute: {0}", minute);
  24.        
  25.         int second = moment.Second;
  26.         Console.WriteLine("Second: {0}", second);      
  27.        
  28.         int millisecond = moment.Millisecond;
  29.         Console.WriteLine("Millisecond: {0}", millisecond);    
  30.        
  31.         Console.WriteLine("------------------------");
  32.         Console.WriteLine(moment);
  33.         DateTime tomorrow = moment.AddDays(1);
  34.         Console.WriteLine(tomorrow);
  35.         Console.WriteLine(moment.AddDays(30));
  36.  
  37.         DateTime birthday = new DateTime(1987,1,23);
  38.         Console.WriteLine(birthday.ToString("MMMM dd, yyyy"));
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement