How to extract and display the day from DateTime in C#

3 Answers

0 votes
using System;

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

            string day = now.ToString("d ");

            Console.WriteLine($"{day}");
        }
    }
}


/*
run:
 
14

*/

 



answered Aug 14, 2018 by avibootz
0 votes
using System;
using System.Globalization;
using System.Threading;

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

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            string hour = now.ToString("ddd ");

            Console.WriteLine($"{hour}");
        }
    }
}


/*
run:
  
Tue
 
*/

 



answered Aug 14, 2018 by avibootz
0 votes
using System;
using System.Globalization;
using System.Threading;

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

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            string hour = now.ToString("dddd ");

            Console.WriteLine($"{hour}");
        }
    }
}


/*
run:
  
Tuesday
 
*/

 



answered Aug 14, 2018 by avibootz

Related questions

1 answer 137 views
2 answers 194 views
2 answers 202 views
1 answer 160 views
1 answer 157 views
1 answer 132 views
1 answer 178 views
...