четверг, 16 апреля 2020 г.

C#, Date, Time and Environment

using System;
using System.Diagnostics;

namespace ConsoleApp3
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var sw = new Stopwatch();
            sw.Start();

            var now = DateTime.Now;
            Console.WriteLine("Now is " + now);

            var today = DateTime.Today;
            Console.WriteLine("Today is " + today.ToLongDateString());
            Console.WriteLine("Tomorrow is " + today.AddDays(1).ToShortDateString());

            Console.WriteLine("Date: " + now.Date);
            Console.WriteLine("Day: " + now.Day);
            Console.WriteLine("Month: " + now.Month);
            Console.WriteLine("Year: " + now.Year);
            Console.WriteLine("Hour: " + now.Hour);
            Console.WriteLine("Minute: " + now.Minute);
            Console.WriteLine("Second: " + now.Second);

            Console.WriteLine("PC Name: " + Environment.MachineName);
            Console.WriteLine("Num of cores: " + Environment.ProcessorCount);
            Console.WriteLine("User: " + Environment.UserName);
            Console.WriteLine("Env var 'OS': " + Environment.GetEnvironmentVariable("OS"));
            Console.WriteLine("Path to MyDoc: " + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

            sw.Stop();
            //Console.WriteLine("Elapsed time: " + sw.Elapsed.ToString("s\\.ffff"));
            Console.WriteLine($"Speed: {sw.Elapsed:s\\.ffff}");
            sw.Reset();

            var rnd = new Random(DateTime.Now.Millisecond);
            for (var i = 0; i < 3; i++)
            {
                Console.WriteLine("1d6: " + rnd.Next(1, 6 + 1));
            }
        }
    }
}

Комментариев нет:

Отправить комментарий