Sets the time of the current date with millisecond precision - CSharp System

CSharp examples for System:DateTime Second

Description

Sets the time of the current date with millisecond precision

Demo Code


using System;//from   ww  w  . jav  a2s . c  om

public class Main{
        /// <summary>
      /// Sets the time of the current date with millisecond precision
      /// </summary>
      /// <param name="current">The current date</param>
      /// <param name="hour">The hour</param>
      /// <param name="minute">The minute</param>
      /// <param name="second">The second</param>
      /// <param name="millisecond">The millisecond</param>
      /// <returns></returns>
      public static DateTime SetTime(this DateTime current, int hour, int minute, int second, int millisecond)
      {
         var atTime = new DateTime(current.Year, current.Month, current.Day, hour, minute, second, millisecond);
         return atTime;
      }
        /// <summary>
      /// Sets the time of the current date with second precision
      /// </summary>
      /// <param name="current">The current date</param>
      /// <param name="hour">The hour</param>
      /// <param name="minute">The minute</param>
      /// <param name="second">The second</param>
      /// <returns></returns>
      public static DateTime SetTime(this DateTime current, int hour, int minute, int second)
      {
         return SetTime(current, hour, minute, second, 0);
      }
        /// <summary>
      /// Sets the time of the current date with minute precision
      /// </summary>
      /// <param name="current">The current date</param>
      /// <param name="hour">The hour</param>
      /// <param name="minute">The minute</param>
      public static DateTime SetTime(this DateTime current, int hour, int minute)
      {
         return SetTime(current, hour, minute, 0, 0);
      }
}

Related Tutorials