ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

AddTime

Adds time to existing DateTime

Source

public static DateTime AddTime(this DateTime date, int hour, int minutes)
{
    return date + new TimeSpan(hour, minutes, 0);
}

Example

var today = DateTime.Today;
var myDate = today.AddTime(1, 55);

Author: Cătălin Rădoi

Submitted on: 21 mei 2015

Language: C#

Type: DateTime

Views: 6244