+ 1
Convert.DateTime format
Simple question... (c#) DateTime DataNascita = new DateTime(2010, 1, 1); DataNascita = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine(DataNascita); My date is in mm/dd/yyyy hh.mm.ss format. How i can change to dd/mm/yyyy format without hours/minutes/seconds?
7 Antworten
+ 11
or alternatively, you may write it as:-
DataNascita.ToString("dd/MM/yyyy");
Hopefully it helps! 😉
+ 2
resolved with:
Console.WriteLine(DataNascita.Day + "/" + DataNascita.Month + "/" + DataNascita.Year);
:P
+ 1
Convert.ToDateTime(DateTime.ParseExact("dateString","dd/MM/yyyy",CultureInfo.InvariantCulture));
not sure work.
+ 1
I have add the "using System.Globalization;" and the compile run but I still see the MM/dd/yyyy hh:mm:ss format... :|
0
..\Playground\(28,84): error CS0103: The name 'CultureInfo' does not exist in the current context
0
I had only one problem now....
wirh value of one number, like 6, Console.WriteLine(DataNascita.Day give my "6".
How i can obtain "06" ?
0
resolved with
Giorno = Convert.ToString(DataNascita.Day);
if(Giorno.Length < 2)
{
Giorno = "0" + Giorno;
}