repl.it
@kironroy/

datetime

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;


class MainClass {
  public static void Main (string[] args) {
   
  // var datetime = new DateTime(2018, 8, 16);
   var now = DateTime.Now;
   //var today = DateTime.Today;

  Console.WriteLine("Hour: " + now.Hour);
  Console.WriteLine("Minute: " + now.Minute);
  Console.WriteLine();

  
  Console.WriteLine(" ------ Date Span Below ------ ");  

  var tommorrow = now.AddDays(1);
  var yesterday = now.AddDays(-1);

  Console.WriteLine("----------------------------");
  Console.WriteLine();
  
  Console.WriteLine("Today is: " + now);
  Console.WriteLine("Yesterday was: " + yesterday);
  Console.WriteLine("Tommorrow will be: " + tommorrow);
  
  Console.WriteLine();
  Console.WriteLine("----------------------------");

  Console.WriteLine(now.ToLongTimeString());

  Console.WriteLine(" ------ Time Span Below ------ ");   
    
  Console.WriteLine();

  var timeSpan = new TimeSpan(1, 2, 3); // hour, minutes, seconds    
  
  var timeSpan1 = new TimeSpan(1, 0, 0);
  var timeSpan2 = TimeSpan.FromHours(1);

  // Creating
  
  var start = DateTime.Now;
  var end = DateTime.Now.AddMinutes(2);
  var duration = end - start;
  Console.WriteLine("Duration: " + duration);

 // Properties

 Console.WriteLine("Minutes: " + timeSpan.Minutes);
 Console.WriteLine("Total Minutes: " + timeSpan.TotalMinutes);

 // Add 
 
 Console.WriteLine("Add Example: " + timeSpan.Add(TimeSpan.FromMinutes(8)));
 Console.WriteLine("Subtract Example: " + timeSpan.Subtract(TimeSpan.FromMinutes(2)));

 // ToString 

 Console.WriteLine("ToString: " + timeSpan.ToString());

 // Parse 

 Console.WriteLine("Parse: " + TimeSpan.Parse("01:02:03"));



 




  
  
  
  
  
  
  
  
  
  
  
  }
}