DateTime devuelve una fecha incorrecta
Frecuentes
Visto 3,462 equipos
5 Respuestas
5
Usar new DateTime()
creates a DateTime with a time of "0".
If you want todays date you need to use DateTime.Today
if you want a DateTime object with a date of today and a time of 12:00:00 AM or DateTime.Now
if you want a DateTime with the day and time of the moment you called DateTime.Now
.
contestado el 28 de mayo de 14 a las 14:05
2
Según MSDN, el constructor for DateTime which takes in a long initializes by using the specified number of ticks since 1st enero, 0001, so saying new DateTime(0)
yields this time, not the current time.
Instead, use the static field DateTime.Ahora conseguir un DateTime representing the current system time.
Respondido 07 Feb 17, 11:02
0
In your question you are just initializing the Variable todayDateTime but you have never assigned (set it). This is why it is date ("null")/ beginning of our time calculations.
To actually get todays Date, you can use the following:
DateTime today = DateTime.Today;
Respondido el 25 de Septiembre de 18 a las 13:09
0
first of all you need to assigned a value in the datetime. just use something like this :
DateTime today = DateTime.Today;
Respondido 30 Abr '20, 22:04
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# datetime or haz tu propia pregunta.
Show your code as well. It is the value of
DateTime.MinValue
campo. - Soner GönülDateTime todayDateTime = new DateTime(); - Rui Martins
A diferencia de Java
DateTime todayDateTime = new Date()
which creates current datetime, C# returns "zero" datetime; useDateTime todayDateTime = DateTime.Now;
in C# instead - Dmitry Bychenko