Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Test0_34
- {
- class Program
- {
- static void Main(string[] args)
- {
- var a = 1532655487231;
- var b = 7456328877414;
- var c = Math.Abs(a - b);
- Console.WriteLine("Time Between A and B");
- Console.WriteLine("In seconds: {0}", c);
- Console.WriteLine("In minutes: {0}", c / 60);
- Console.WriteLine("In hours: {0}", c / 60 / 60);
- Console.WriteLine("In days: {0}", c / 60 / 60 / 24);
- Console.WriteLine("In weeks: {0}", c / 60 / 60 / 24 / 7);
- Console.WriteLine("In months: {0}", c / 60 / 60 / 24 / 30);
- Console.WriteLine("In years: {0}", c / 60 / 60 / 24 / 365);
- Console.WriteLine("In millenia: {0}", c / 60 / 60 / 24 / 365 / 1000);
- Console.WriteLine("");
- Console.WriteLine("------------------");
- Console.WriteLine("");
- Console.WriteLine("Pretty Print Time");
- Func<long, string> timeToString = t =>
- {
- var millenia = t / (60L * 60 * 24 * 365 * 1000);
- t = t % (60L * 60 * 24 * 365 * 1000);
- var years = t / (60L * 60 * 24 * 365);
- t = t % (60L * 60 * 24 * 365);
- var months = t / (60L * 60 * 24 * 30);
- t = t % (60L * 60 * 24 * 30);
- var weeks = t / (60L * 60 * 24 * 7);
- t = t % (60L * 60 * 24 * 7);
- var days = t / (60L * 60 * 24);
- t = t % (60L * 60 * 24);
- var hours = t / (60L * 60);
- t = t % (60L * 60);
- var mins = t / (60L);
- var seconds = t % (60L);
- return string.Concat(
- millenia > 0 ? millenia.ToString() : "",
- millenia > 0 ? " millenia " : "",
- years > 0 ? years.ToString() : "",
- years > 0 ? " years " : "",
- months > 0 ? months.ToString() : "",
- months > 0 ? " months " : "",
- weeks > 0 ? weeks.ToString() : "",
- weeks > 0 ? " weeks " : "",
- days > 0 ? days.ToString() : "",
- days > 0 ? " days " : "",
- hours > 0 ? hours.ToString() : "",
- hours > 0 ? " hours " : "",
- mins > 0 ? mins.ToString() : "",
- mins > 0 ? " minutes " : "",
- seconds > 0 ? seconds.ToString() : "",
- seconds > 0 ? " seconds " : ""
- );
- };
- Console.WriteLine("a {0}", timeToString(a));
- Console.WriteLine("b {0}", timeToString(b));
- Console.WriteLine("c {0}", timeToString(c));
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement