Basic usage:

// ***

// *** Initialize a new default Time instance.

// ***

Time t0 = Time.Empty;

Console.WriteLine("t0 = {0}", t0);

 

// ***

// *** Initialize a time using a standard string format

// *** (anything that is parse-able by DateTime)

// ***

Time t1 = "11:35 AM";

Console.WriteLine("t1 = {0}", t1);

 

// ***

// *** Initialize a time using a standard string format

// *** (anything that is parse-able by TimeSpan)

// ***

Time t2 = "14:05";

Console.WriteLine("t2 = {0}", t2);

 

// ***

// *** Get the Time from a DateTime instance

// ***

Time t3 = DateTime.Now;

Console.WriteLine("t3 = {0}", t3);

 

// ***

// *** Get a DateTime for yesterday using the specified time.

// ***

DateTime yesterday = DateTime.Now.Subtract(TimeSpan.FromDays(1)).Date + t1;

Console.WriteLine("yesterday = {0}", yesterday);

Output:

t0 = 12:00 AM
t1 = 11:35 AM
t2 = 2:05 PM
t3 = 8:25 AM
yesterday = 8/24/2013 11:35:00 AM

Last edited Aug 2, 2014 at 4:24 PM by porrey, version 4

Comments

No comments yet.