Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Liquid Web iThemes WordPress Hosting

Website Domains Names & Hosting | Domain.com

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

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

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

12,195 questions

16,607 answers

573 users

How to print formatted date & time in C#

Online Web Development & Programming Courses | Udemy
38 views
asked Feb 18, 2015 by avibootz
edited Aug 14, 2018 by avibootz

10 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2015, 2, 18, 3, 40, 5);

            string s = dt.ToString("d");
            Console.WriteLine(s);   // 2/18/2015
        }
    }
}

/*
run:
 
2/18/2015

*/



answered Feb 18, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2015, 2, 18, 3, 40, 5);

            Console.WriteLine("{0:d}", dt);  // 2/18/2015 // MM/dd/yyyy
        }
    }
}

/*
run:
 
2/18/2015

*/



answered Feb 18, 2015 by avibootz
edited Feb 18, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2015, 2, 18, 3, 40, 5);

            Console.WriteLine("{0:D}", dt);  // Wednesday, February 18, 2015 // Dd MMMM yyyy
        }
    }
}

/*
run:
 
Wednesday, February 18, 2015

*/



answered Feb 18, 2015 by avibootz
edited Feb 18, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2015, 2, 18, 3, 40, 5);

            Console.WriteLine("{0:f}", dt);  // Wednesday, February 18, 2015 3:40 AM 
                                             // Dd MMMM yyyy HH:mm
        }
    }
}

/*
run:
 
Wednesday, February 18, 2015 3:40 AM

*/



answered Feb 18, 2015 by avibootz
edited Jun 9, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2015, 2, 18, 3, 40, 5);

            Console.WriteLine("{0:F}", dt); // Wednesday, February 18, 2015 3:40:05 AM 
                                            // Dd MMMM yyyy HH:mm:ss
        }
    }
}

/*
run:
 
Wednesday, February 18, 2015 3:40:05 AM

*/



answered Feb 18, 2015 by avibootz
edited Jun 9, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(String.Format("{0:d/M/yyyy HH:mm:ss}", DateTime.Now));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:

9/6/2015 18:41:35
 
*/

 




answered Jun 9, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(DateTime.Now.ToString("MMM ddd yyyy - HH:mm"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:

Jun Tue 2015 - 18:59
 
*/

 




answered Jun 9, 2015 by avibootz
edited Jun 9, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(DateTime.Now.ToString("M/d/yy - h:mm"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:

6/9/15 - 7:00
 
*/

 




answered Jun 9, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                DateTime now = DateTime.Now;

                Console.WriteLine(now.ToString("d")); // 6/9/2015
                Console.WriteLine(now.ToString("D")); // Tuesday, June 09, 2015
                Console.WriteLine(now.ToString("f")); // Tuesday, June 09, 2015 7:04 PM
                Console.WriteLine(now.ToString("F")); // Tuesday, June 09, 2015 7:04:07 PM
                Console.WriteLine(now.ToString("g")); // 6/9/2015 7:04 PM
                Console.WriteLine(now.ToString("G")); // 6/9/2015 7:04:07 PM
                Console.WriteLine(now.ToString("m")); // June 09
                Console.WriteLine(now.ToString("o")); // 2015-06-09T19:04:07.5311601+03:00
                Console.WriteLine(now.ToString("s")); // 2015-06-09T19:04:07
                Console.WriteLine(now.ToString("t")); // 7:04 PM
                Console.WriteLine(now.ToString("T")); // 7:04:07 PM
                Console.WriteLine(now.ToString("u")); // 2015-06-09 19:04:07Z
                Console.WriteLine(now.ToString("U")); // Tuesday, June 09, 2015 4:04:07 PM
                Console.WriteLine(now.ToString("y")); // June, 2015
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:

6/9/2015
Tuesday, June 09, 2015
Tuesday, June 09, 2015 7:04 PM
Tuesday, June 09, 2015 7:04:07 PM
6/9/2015 7:04 PM
6/9/2015 7:04:07 PM
June 09
2015-06-09T19:04:07.5311601+03:00
2015-06-09T19:04:07
7:04 PM
7:04:07 PM
2015-06-09 19:04:07Z
Tuesday, June 09, 2015 4:04:07 PM
June, 2015
 
*/

 




answered Jun 9, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                DateTime now = DateTime.Now;

                Console.WriteLine(now.ToLongDateString());  // Tuesday, June 09, 2015
                Console.WriteLine(now.ToLongTimeString());  // 7:07:45 PM
                Console.WriteLine(now.ToShortDateString()); // 6/9/2015
                Console.WriteLine(now.ToShortTimeString()); // 7:07 PM
                Console.WriteLine(now.ToString());          // 6/9/2015 7:07:45 PM
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:

Tuesday, June 09, 2015
7:07:45 PM
6/9/2015
7:07 PM
6/9/2015 7:07:45 PM
 
*/

 




answered Jun 9, 2015 by avibootz
...