Use the property Environment.TickCount, in order to get the count of passed milliseconds. Use the fact that one second has 1,000 milliseconds; one minute has 60 seconds; one hour has 60 minutes and one day has 24 hours.
Loading
Use the property Environment.TickCount, in order to get the count of passed milliseconds. Use the fact that one second has 1,000 milliseconds; one minute has 60 seconds; one hour has 60 minutes and one day has 24 hours.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Uday DodiyaRank #239 · 10.3K reputationPosted Oct 23, 2023, 2:42 AM EDT
Try This
using System; class Program { static void Main() { int milliseconds = Environment.TickCount; // Calculate seconds, minutes, hours, and days int seconds = milliseconds / 1000; int minutes = seconds / 60; int hours = minutes / 60; int days = hours / 24; // Calculate the remaining milliseconds, seconds, minutes, and hours int remainingMilliseconds = milliseconds % 1000; int remainingSeconds = seconds % 60; int remainingMinutes = minutes % 60; int remainingHours = hours % 24; Console.WriteLine("Milliseconds: " + remainingMilliseconds); Console.WriteLine("Seconds: " + remainingSeconds); Console.WriteLine("Minutes: " + remainingMinutes); Console.WriteLine("Hours: " + remainingHours); Console.WriteLine("Days: " + days); } }This code will calculate and display the number of milliseconds, seconds, minutes, hours, and days using the Environment.TickCount property in C#.
Sarthak VarshneyRank #46 · 32K reputationPosted Oct 21, 2023, 10:09 AM EDT
You can create a simple C# program to print the count of days using the Environment.TickCount property to measure the number of milliseconds that have passed and then convert it to days. Here's a sample C# program to achieve this:
using System; class Program { static void Main() { int milliseconds = Environment.TickCount; int seconds = milliseconds / 1000; int minutes = seconds / 60; int hours = minutes / 60; int days = hours / 24; Console.WriteLine($"Count of days: {days}"); } }This program first retrieves the number of milliseconds using
Environment.TickCount, then it converts that into seconds, minutes, hours, and finally, days based on the given conversion factors. It then prints the count of days to the standard output.