Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

How to represent today's date and time in different forms with C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string[] months = {"January", "February", "March", "April", "May", "June", "July",
                           "August", "September", "October", "November", "December"};

        DateTime now = DateTime.Now;
    
        Console.WriteLine("{0}", now.Date);
        Console.WriteLine("{0} day of {1}", now.Day, months[now.Month - 1]);
        Console.WriteLine("{0} day of {1}", now.DayOfYear, now.Year);
        Console.WriteLine("{0}", now.TimeOfDay);
        Console.WriteLine("{0}:{1}:{2}.{3}", now.Hour, now.Minute, now.Second, now.Millisecond);
        Console.WriteLine("{0}", now.DayOfWeek);
    }
}




/*
run:

7/8/2023 12:00:00 AM
8 day of July
189 day of 2023
06:22:08.7438490
6:22:8.743
Saturday

*/

 



answered Jul 8, 2023 by avibootz
edited Jul 8, 2023 by avibootz

Related questions

...