Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

13,285 questions

18,078 answers

573 users

How to print a DateTime array in C#

4 Answers

0 votes
using System;

class Program
{
    static void Main() {
        DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2020, 5, 18, 11, 09, 30),
            new DateTime(2019, 7, 22),
            new DateTime(2018, 6, 14, 13, 27, 05),
        };
        
        Console.WriteLine(dateTimes[0] + "\n");
        Console.WriteLine(dateTimes[1] + "\n");
        Console.WriteLine(dateTimes[1] + "\n");
    }
}



/*
run:

5/18/2020 11:09:30 AM

7/22/2019 12:00:00 AM

7/22/2019 12:00:00 AM

*/

 




answered May 18 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2020, 5, 18, 11, 09, 30),
            new DateTime(2019, 7, 22),
            new DateTime(2018, 6, 14, 13, 27, 05),
        };
        
        foreach (DateTime dt in dateTimes)
            Console.WriteLine(dt);
    }
}



/*
run:

5/18/2020 11:09:30 AM
7/22/2019 12:00:00 AM
6/14/2018 1:27:05 PM

*/

 




answered May 18 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2020, 5, 18, 11, 09, 30),
            new DateTime(2019, 7, 22),
            new DateTime(2018, 6, 14, 13, 27, 05, 30),
        };
        
        for (int i = 0; i < dateTimes.Length; i++) {
            Console.Write("{0}/{1}/{2}\n", dateTimes[i].Day, dateTimes[i].Month, 
                                           dateTimes[i].Year);
            Console.Write("{0}:{1}:{2} {3}\n", dateTimes[i].Hour, dateTimes[i].Minute, 
                                               dateTimes[i].Second, dateTimes[i].Millisecond);
        }
    }
}



/*
run:

18/5/2020
11:9:30 0
22/7/2019
0:0:0 0
14/6/2018
13:27:5 30

*/

 




answered May 18 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2020, 5, 18, 11, 09, 30),
            new DateTime(2019, 7, 22),
            new DateTime(2018, 6, 14, 13, 27, 05, 33),
        };
        
        for (int i = 0; i < dateTimes.Length; i++) {
            Console.WriteLine(dateTimes[i].ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK"));
        }
    }
}



/*
run:

2020-05-18T11:09:30.0000000
2019-07-22T00:00:00.0000000
2018-06-14T13:27:05.0330000

*/

 




answered May 18 by avibootz
...