I\'m trying to create a string from the DateTime object which yields the format mm:dd:yyyy
.
Conventionally the DateTime
object comes as
Usually, I am using DateTime.ToShortDateString() to convert in a Culture
-aware manner to a string.
This way, you can format it to date only respecting the current formatting of the culture set to the current thread.
datetime DateWithTimeNoSeconds =
DateTime.Now.Date.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute);
This gets the current date & time's date and adds hours and minutes.
Something like this for date and time without seconds:
private DateTime _startTime;
public DateTime StartTime
{
get { return _startTime; }
set
{
_startTime = value.AddSeconds(-value.Second)
.AddMilliseconds(-value.Millisecond);
}
}