I need to create an object of type DateTime that contains only Day , Month and Time . It may even take minutes and seconds but can not have Year.
How do I do this?
I need to create an object of type DateTime that contains only Day , Month and Time . It may even take minutes and seconds but can not have Year.
How do I do this?
Well, you can create your own type - but a DateTime always has complete date and time. You can always ignore the year - or use the current year:
DateTime data = new DateTime(DateTime.Now.Year, mes, dia);
To create your own type you can do something similar to this:
public struct MesDia : IEquatable<MesDia>
{
private readonly DateTime data;
public MesDia(int mes, int dia)
{
data = new DateTime(2018, mes, dia);
}
public MesDia AddDays(int dia)
{
DateTime added = data.AddDays(dia);
return new MesDia(added.Month, added.Day);
}
public bool Equals(MesDia other)
{
//implementar;
}
}