C# Sharp Exercises: Display the number of ticks TimeSpan object using the Ticks property
C# Sharp DateTime : Exercise-6 with Solution
Write a C# Sharp program to display the number of ticks that have elapsed since the beginning of the twenty-first century and to instantiate a TimeSpan object using the Ticks property.
Note: The TimeSpan object is then used to display the elapsed time using several other time intervals.
Sample Solution:-
C# Sharp Code:
using System;
using System.Globalization;
public class Example6
{
public static void Main()
{
DateTime localDate = DateTime.Now;
DateTime utcDate = DateTime.UtcNow;
String[] cultureNames = { "en-JM", "en-NZ", "fr-BE",
"de-CH", "nl-NL" } ;
foreach (var cultureName in cultureNames) {
var culture = new CultureInfo(cultureName);
Console.WriteLine("{0}:", culture.NativeName);
Console.WriteLine(" Local date and time: {0}, {1:G}",
localDate.ToString(culture), localDate.Kind);
Console.WriteLine(" UTC date and time: {0}, {1:G}\n",
utcDate.ToString(culture), utcDate.Kind);
}
}
}
Sample Output:
English (Jamaica): Local date and time: 09/06/2017 18:20:08, Local UTC date and time: 09/06/2017 12:50:08, Utc English (New Zealand): Local date and time: 9/06/2017 6:20:08 p.m., Local UTC date and time: 9/06/2017 12:50:08 p.m., Utc français (Belgique): Local date and time: 09-06-17 18:20:08, Local UTC date and time: 09-06-17 12:50:08, Utc Deutsch (Schweiz): Local date and time: 09.06.2017 18:20:08, Local UTC date and time: 09.06.2017 12:50:08, Utc Nederlands (Nederland): Local date and time: 9-6-2017 18:20:08, Local UTC date and time: 9-6-2017 12:50:08, Utc
Flowchart :

C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to get a DateTime value that represents the current date and time on the local computer.
Next: Write a C# Sharp program to get the time of day from a given array of date time values.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Exercises: Weekly Top 12 Most Popular Topics
- Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
- SQL Exercises, Practice, Solution - SUBQUERIES
- C Programming Exercises, Practice, Solution : For Loop
- Python Exercises, Practice, Solution
- Python Data Type: List - Exercises, Practice, Solution
- C++ Basic: Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - exercises on Employee Database
- SQL Exercises, Practice, Solution - exercises on Movie Database
- SQL Exercises, Practice, Solution - exercises on Soccer Database
- C Programming Exercises, Practice, Solution : Recursion